{"action":"created","issue":{"url":"https://api.github.com/repos/ethereum/EIPs/issues/225","repository_url":"https://api.github.com/repos/ethereum/EIPs","labels_url":"https://api.github.com/repos/ethereum/EIPs/issues/225/labels{/name}","comments_url":"https://api.github.com/repos/ethereum/EIPs/issues/225/comments","events_url":"https://api.github.com/repos/ethereum/EIPs/issues/225/events","html_url":"https://github.com/ethereum/EIPs/issues/225","id":212094213,"node_id":"MDU6SXNzdWUyMTIwOTQyMTM=","number":225,"title":"Clique PoA protocol & Rinkeby PoA testnet","user":{"login":"karalabe","id":129561,"node_id":"MDQ6VXNlcjEyOTU2MQ==","avatar_url":"https://avatars2.githubusercontent.com/u/129561?v=4","gravatar_id":"","url":"https://api.github.com/users/karalabe","html_url":"https://github.com/karalabe","followers_url":"https://api.github.com/users/karalabe/followers","following_url":"https://api.github.com/users/karalabe/following{/other_user}","gists_url":"https://api.github.com/users/karalabe/gists{/gist_id}","starred_url":"https://api.github.com/users/karalabe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/karalabe/subscriptions","organizations_url":"https://api.github.com/users/karalabe/orgs","repos_url":"https://api.github.com/users/karalabe/repos","events_url":"https://api.github.com/users/karalabe/events{/privacy}","received_events_url":"https://api.github.com/users/karalabe/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":107,"created_at":"2017-03-06T11:24:17Z","updated_at":"2018-12-05T12:24:00Z","closed_at":null,"author_association":"MEMBER","body":"# Changelog:\r\n\r\n * **Apr 4, 2017**:\r\n   * Mention the cascading proposal-execution corner case and its avoidance.\r\n * **Mar 14, 2017**:\r\n   * Expanded the Clique block authorization section, added a strategy proposal.\r\n   * Expanded the Clique signer voting section, added a strategy proposal.\r\n * **Mar 13, 2017**:\r\n   * Polished up the constants in the Clique consensus protocol spec.\r\n   * Added the two difficulty values and described in-turn/out-of-turn signing.\r\n * **Mar 11, 2017**:\r\n   * Added initial technical specs for the Clique PoA consensus protocol.\r\n   * Added checkpointing to reset votes and embed the list of signers into epoch headers.\r\n   * Reintroduced authorized signer vanity extra-data as a fixed 32 byte allowance.\r\n * **Mar 6, 2017**\r\n   * First proposal of the Rinkeby testnet and its PoA implementation ideas.\r\n\r\n# Clique proof-of-authority consensus protocol\r\n\r\n*Note, for the background and rationale behind the proposed proof-of-authority consensus protocol, please read the sections after this technical specification. I've placed this on top to have an easy to find reference for implementers without having to dig through the discussions.*\r\n\r\nWe define the following constants:\r\n\r\n * **`EPOCH_LENGTH`**: Number of blocks after which to checkpoint and reset the pending votes.\r\n   * Suggested `30000` for the testnet to remain analogous to the mainnet `ethash` epoch.\r\n * **`BLOCK_PERIOD`**: Minimum difference between two consecutive block's timestamps.\r\n   * Suggested `15s` for the testnet to remain analogous to the mainnet `ethash` target.\r\n * **`EXTRA_VANITY`**: Fixed number of extra-data prefix bytes reserved for signer *vanity*.\r\n   * Suggested `32 bytes` to retain the current extra-data allowance and/or use.\r\n * **`EXTRA_SEAL`**: Fixed number of extra-data suffix bytes reserved for signer seal.\r\n   * `65 bytes` fixed as signatures are based on the standard `secp256k1` curve.\r\n * **`NONCE_AUTH`**: Magic nonce number `0xffffffffffffffff` to vote on adding a new signer.\r\n * **`NONCE_DROP`**: Magic nonce number `0x0000000000000000` to vote on removing a signer.\r\n * **`UNCLE_HASH`**: Always `Keccak256(RLP([]))` as uncles are meaningless outside of PoW.\r\n * **`DIFF_NOTURN`**: Block score (difficulty) for blocks containing out-of-turn signatures.\r\n   * Suggested `1` since it just needs to be an arbitrary baseline constant.\r\n * **`DIFF_INTURN`**: Block score (difficulty) for blocks containing in-turn signatures.\r\n   * Suggested `2` to show a slight preference over out-of-turn signatures.\r\n\r\nWe also define the following per-block constants:\r\n\r\n * **`BLOCK_NUMBER`**: Block height in the chain, where the height of the genesis is block `0`.\r\n * **`SIGNER_COUNT`**: Number of authorized signers valid at a particular instance in the chain.\r\n * **`SIGNER_INDEX`**: Index of the block signer in the sorted list of current authorized signers.\r\n * **`SIGNER_LIMIT`**: Number of consecutive blocks out of which a signer may only sign one.\r\n   * Must be `floor(SIGNER_COUNT / 2) + 1` to enforce majority consensus on a chain.\r\n\r\nWe repurpose the `ethash` header fields as follows:\r\n\r\n * **`beneficiary`**: Address to propose modifying the list of authorized signers with.\r\n   * Should be filled with zeroes normally, modified only while voting.\r\n   * Arbitrary values are permitted nonetheless (even meaningless ones such as voting out non signers) to avoid extra complexity in implementations around voting mechanics.\r\n   * **Must** be filled with zeroes on checkpoint (i.e. epoch transition) blocks.\r\n * **`nonce`**: Signer proposal regarding the account defined by the `beneficiary` field.\r\n   * Should be **`NONCE_DROP`** to propose deauthorizing `beneficiary` as a existing signer.\r\n   * Should be **`NONCE_AUTH`** to propose authorizing `beneficiary` as a new signer.\r\n   * **Must** be filled with zeroes on checkpoint (i.e. epoch transition) blocks.\r\n   * **Must** not take up any other value apart from the two above (for now).\r\n * **`extraData`**: Combined field for signer vanity, checkpointing and signer signatures.\r\n   * First **`EXTRA_VANITY`** bytes (fixed) may contain arbitrary signer vanity data.\r\n   * Last **`EXTRA_SEAL`** bytes (fixed) is the signer's signature sealing the header.\r\n   * Checkpoint blocks **must** contain a list of signers (`N*20 bytes`) in between, **omitted** otherwise.\r\n   * The list of signers in checkpoint block extra-data sections **must** be sorted in ascending order.\r\n * **`mixHash`**: Reserved for fork protection logic, similar to the extra-data during the DAO.\r\n   * **Must** be filled with zeroes during normal operation.\r\n * **`ommersHash`**: **Must** be **`UNCLE_HASH`** as uncles are meaningless outside of PoW.\r\n * **`timestamp`**: **Must** be at least the parent timestamp + **`BLOCK_PERIOD`**.\r\n * **`difficulty`**: Contains the standalone score of the block to derive the quality of a chain.\r\n   * **Must** be **`DIFF_NOTURN`** if `BLOCK_NUMBER % SIGNER_COUNT != SIGNER_INDEX`\r\n   * **Must** be **`DIFF_INTURN`** if `BLOCK_NUMBER % SIGNER_COUNT == SIGNER_INDEX`\r\n\r\n## Authorizing a block\r\n\r\nTo authorize a block for the network, the signer needs to sign the block's hash containing **everything except the signature itself**. The means that the hash contains every field of the header (`nonce` and `mixDigest` included), and also the  `extraData` with the exception of the 65 byte signature suffix. The fields are hashed in the order of their definition in the yellow paper.\r\n\r\nThis hash is signed using the standard `secp256k1` curve, and the resulting 65 byte signature (`R`, `S`, `V`, where `V` is `0` or `1`) is embedded into the `extraData` as the trailing 65 byte suffix.\r\n\r\nTo ensure malicious signers (loss of signing key) cannot wreck havoc in the network, each singer is allowed to sign **maximum one** out of **`SIGNER_LIMIT`** consecutive blocks. The order is not fixed, but in-turn signing weighs more (**`DIFF_INTURN`**) than out of turn one (**`DIFF_NOTURN`**).\r\n\r\n### Authorization strategies\r\n\r\nAs long as signers conform to the above specs, they can authorize and distribute blocks as they see fit. The following suggested strategy will however reduce network traffic and small forks, so it's a suggested feature:\r\n\r\n * If a signer is allowed to sign a block (is on the authorized list and didn't sign recently).\r\n   * Calculate the optimal signing time of the next block (parent + **`BLOCK_PERIOD`**).\r\n   * If the signer is in-turn, wait for the exact time to arrive, sign and broadcast immediately.\r\n   * If the signer is out-of-turn, delay signing by `rand(SIGNER_COUNT * 500ms)`.\r\n\r\nThis small strategy will ensure that the in-turn signer (who's block weighs more) has a slight advantage to sign and propagate versus the out-of-turn signers. Also the scheme allows a bit of scale with the increase of the number of signers.\r\n\r\n## Voting on signers\r\n\r\nEvery epoch transition (genesis block included) acts as a stateless checkpoint, from which capable clients should be able to sync without requiring any previous state. This means epoch headers **must not** contain votes, all non settled votes are discarded, and tallying starts from scratch.\r\n\r\nFor all non-epoch transition blocks:\r\n\r\n * Signers may cast one vote per own block to propose a change to the authorization list.\r\n * Only the latest proposal per target beneficiary is kept from a single signer.\r\n * Votes are tallied live as the chain progresses (concurrent proposals allowed).\r\n * Proposals reaching majority consensus **`SIGNER_LIMIT`** come into effect immediately.\r\n * Invalid proposals are **not** to be penalized for client implementation simplicity.\r\n\r\n**A proposal coming into effect entails discarding all pending votes for that proposal (both for and against) and starting with a clean slate.**\r\n\r\n### Cascading votes\r\n\r\nA complex corner case may arise during signer deauthorization. When a previously authorized signer is dropped, the number of signers required to approve a proposal might decrease by one. This might cause one or more pending proposals to reach majority consensus, the execution of which might further cascade into new proposals passing.\r\n\r\nHandling this scenario is non obvious when multiple conflicting proposals pass simultaneously (e.g. add a new signer vs. drop an existing one), where the evaluation order might drastically change the outcome of the final authorization list. Since signers may invert their own votes in every block they mint, it's not so obvious which proposal would be \"first\".\r\n\r\nTo avoid the pitfalls cascading executions would entail, the Clique proposal explicitly forbids cascading effects. In other words: **Only the `beneficiary` of the current header/vote may be added to/dropped from the authorization list. If that causes other proposals to reach consensus, those will be executed when their respective beneficiaries are \"touched\" again (given that majority consensus still holds at that point).**\r\n\r\n### Voting strategies\r\n\r\nSince the blockchain can have small reorgs, a naive voting mechanism of \"cast-and-forget\" may not be optimal, since a block containing a singleton vote may not end up on the final chain.\r\n\r\nA simplistic but working strategy is to allow users to configure \"proposals\" on the signers (e.g. \"add 0x...\", \"drop 0x...\"). The signing code can then pick a random proposal for every block it signs and inject it. This ensures that multiple concurrent proposals as well as reorgs get eventually noted on the chain.\r\n\r\nThis list may be expired after a certain number of blocks / epochs, but it's important to realize that \"seeing\" a proposal pass doesn't mean it won't get reorged, so it should not be immediately dropped when the proposal passes.\r\n\r\n# Background\r\n\r\nEthereum's first official testnet was Morden. It ran from July 2015 to about November 2016, when due to the accumulated junk and some testnet consensus issues between Geth and Parity, it was finally laid to rest in favor of a testnet reboot.\r\n\r\nRopsten was thus born, clearing out all the junk and starting with a clean slate. This ran well until the end of February 2017, when malicious actors decided to abuse the low PoW and gradually inflate the block gas limits to 9 billion (from the normal 4.7 million), at which point sending in gigantic transactions crippling the entire network. Even before that, attackers attempted multiple extremely long reorgs, causing network splits between different clients, and even different versions.\r\n\r\nThe root cause of these attacks is that a PoW network is only as secure as the computing capacity placed behind it. Restarting a new testnet from zero wouldn't solve anything, since the attacker can mount the same attack over and over again. The Parity team decided to go with an emergency solution of rolling back a significant number of blocks, and enacting a soft-fork rule that disallows gas limits above a certain threshold.\r\n\r\nWhile this solution may work in the short term:\r\n\r\n * It's not elegant: Ethereum supposed to have dynamic block limits\r\n * It's not portable: other clients need to implement new fork logic themselves\r\n * It's not compatible with sync modes: fast and light clients are both out of luck\r\n * It's just prolonging the attacks: junk can still be steadily pushed in ad infinitum\r\n \r\nParity's solution although not perfect, is nonetheless workable. I'd like to propose a longer term alternative solution, which is more involved, yet should be simple enough to allow rolling out in a reasonable amount of time.\r\n\r\n# Standardized proof-of-authority\r\n\r\nAs reasoned above, proof-of-work cannot work securely in a network with no value. Ethereum has its long term goal of proof-of-stake based on Casper, but that is heavy research so we cannot rely on that any time soon to fix today's problems. One solution however is easy enough to implement, yet effective enough to fix the testnet properly, namely a proof-of-authority scheme.\r\n\r\n*Note, Parity does have an [implementation of PoA](https://github.com/ethcore/parity/wiki/Consensus-Engines#authority-round), though it seems more complex than needed and without much documentation on the protocol, it's hard to see how it could play along with other clients. I welcome feedback from them on this proposal from their experience.*\r\n\r\nThe main design goals of the PoA protocol described here is that it should be very simple to implement and embed into any existing Ethereum client, while at the same time allow using existing sync technologies (fast, light, warp) without needing client developers to add custom logic to critical software.\r\n\r\n## Proof-of-authority 101\r\n\r\nFor those not aware of how PoA works, it's a very simplistic protocol, where instead of miners racing to find a solution to a difficult problem, authorized signers can at any time at their own discretion create new blocks.\r\n\r\nThe challenges revolve around how to control minting frequency, how to distribute minting load (and opportunity) between the various signers and how to dynamically adapt the list of signers. The next section defines a proposed protocol to handle all these scenarios.\r\n\r\n## Rinkeby proof-of-authority\r\n\r\nThere are two approaches to syncing a blockchain in general:\r\n\r\n * The classical approach is to take the genesis block and crunch through all the transactions one by one. This is tried and proven, but in Ethereum complexity networks quickly turns out to be very costly computationally.\r\n * The other is to only download the chain of block headers and verify their validity, after which point an arbitrary recent state may be downloaded from the network and checked against recent headers.\r\n \r\nA PoA scheme is based on the idea that blocks may only be minted by trusted signers. As such, every block (or header) that a client sees can be matched against the list of trusted signers. The challenge here is how to maintain a list of authorized signers that can change in time? The obvious answer (store it in an Ethereum contract) is also the wrong answer: fast, light and warp sync don't have access to the state during syncing.\r\n\r\n**The protocol of maintaining the list of authorized signers must be fully contained in the block headers.**\r\n\r\nThe next obvious idea would be to change the structure of the block headers so it drops the notions of PoW, and introduces new fields to cater for voting mechanisms. This is also the wrong answer: changing such a core data structure in multiple implementations would be a nightmare development, maintenance and security wise.\r\n\r\n**The protocol of maintaining the list of authorized signers must fit fully into the current data models.**\r\n\r\nSo, according to the above, we can't use the EVM for voting, rather have to resort to headers. And we can't change header fields, rather have to resort to the currently available ones. Not much wiggle room.\r\n\r\n### Repurposing header fields for signing and voting\r\n\r\nThe most obvious field that currently is used solely as *fun metadata* is the 32 byte **extra-data** section in block headers. Miners usually place their client and version in there, but some fill it with alternative \"messages\". The protocol would extend this field ~~to~~ with 65 bytes with the purpose of a secp256k1 miner signature. This would allow anyone obtaining a block to verify it against a list of authorized signers. It also makes the **miner** section in block headers obsolete (since the address can be derived from the signature).\r\n\r\n*Note, changing the length of a header field is a non invasive operation as all code (such as RLP encoding, hashing) is agnostic to that, so clients wouldn't need custom logic.*\r\n\r\nThe above is enough to validate a chain, but how can we update a dynamic list of signers. The answer is that we can repurpose the newly obsoleted **miner** field and the PoA obsoleted **nonce** field to create a voting protocol:\r\n\r\n * During regular blocks, both of these fields would be set to zero.\r\n * If a signer wishes to enact a change to the list of authorized signers, it will:\r\n   * Set the **miner** to the signer it wishes to vote about\r\n   * Set the **nonce** to `0` or `0xff...f` to vote in favor of adding or kicking out\r\n   \r\nAny clients syncing the chain can \"tally\" up the votes during block processing, and maintain a dynamically changing list of authorized signers by popular vote. ~~The initial set of signers can be given as genesis chain parameters (to avoid the complexity of deploying an \"initial voters list\" contract in the genesis state).~~\r\n\r\nTo avoid having an infinite window to tally up votes in, and also to allow periodically flushing stale proposals, we can reuse the concept of an epoch from ethash, where every epoch transition flushes all pending votes. Furthermore, these epoch transitions can also act as stateless checkpoints containing the list of current authorized signers within the header extra-data. This permits clients to sync up based only on a checkpoint hash without having to replay all the voting that was done on the chain up to that point. It also allows the genesis header to fully define the chain, containing the list of initial signers.\r\n\r\n### Attack vector: Malicious signer\r\n\r\nIt may happen that a malicious user gets added to the list of signers, or that a signer key/machine is compromised. In such a scenario the protocol needs to be able to defend itself against reorganizations and spamming. The proposed solution is that given a list of N authorized signers, any signer may only mint 1 block out of every K. This ensures that damage is limited, and the remainder of the miners can vote out the malicious user.\r\n\r\n### Attack vector: Censoring signer\r\n\r\nAnother interesting attack vector is if a signer (or group of signers) attempts to censor out blocks that vote on removing them from the authorization list. To work around this, we restrict the allowed minting frequency of signers to 1 out of N/2. This ensures that malicious signers need to control at least 51% of signing accounts, at which case it's game over anyway.\r\n\r\n### Attack vector: Spamming signer\r\n\r\nA final small attack vector is that of malicious signers injecting new vote proposals inside every block they mint. Since nodes need to tally up all votes to create the actual list of authorized signers, they need to track all votes through time. Without placing a limit on the vote window, this could grow slowly, yet unbounded. The solution is to place a ~~moving~~ window of W blocks after which votes are considered stale. ~~A sane window might be 1-2 epochs.~~ We'll call this an epoch.\r\n\r\n### Attack vector: Concurrent blocks\r\n\r\nIf the number of authorized signers are N, and we allow each signer to mint 1 block out of K, then at any point in time N-K+1 miners are allowed to mint. To avoid these racing for blocks, every signer would add a small random \"offset\" to the time it releases a new block. This ensures that small forks are rare, but occasionally still happen (as on the main net). If a signer is caught abusing it's authority and causing chaos, it can be voted out.\r\n\r\n# Notes\r\n\r\n**Does this suggest we use a *censored* testnet?**\r\n\r\nSo and so. The proposal suggests that given the malicious nature of certain actors and given the weakness of the PoW scheme in a \"monopoly money\" network, it is better to have a network with a bit of spam filtering enabled that developers can rely on to test their programs vs. to have a wild wild west chain that dies due to its uselessness.\r\n\r\n**Why standardize proof-of-authority?**\r\n\r\nDifferent clients are better at different scenarios. Go may be awesome in capable server side environments, but CPP may be better suited to run on an RPI Zero. Having a possibility to mix clients in private environments too would be a net win for the ecosystem, as well as being able to participate in a single spamless testnet would be a win for everyone at large.\r\n\r\n**Doesn't manual voting get messy?**\r\n\r\nThis is an implementation detail, but signers may implement contract based voting strategy leveraging the full capabilities of the EVM, only pushing the results into the headers for average nodes to verify.\r\n\r\n# Clarifications and feedback\r\n\r\n  * This proposal does not rule out clients running a PoW based testnet side by side, whether Ropsten or a new one based on it. The ideal scenario would be that clients provide a way to attach to both PoW as well as PoA based test networks (https://github.com/ethereum/EIPs/issues/225#issuecomment-284378473).\r\n * The protocol parameters although can be made configurable at client implementers' discression, the Rinkeby network should be as close to the main network as possible. That includes dynamic gas limits, variable block times around 15 seconds, gas prices and such (https://github.com/ethereum/EIPs/issues/225#issuecomment-284380575).\r\n * The scheme requires that at least K signers are online at any time, since that is the minimum number required to ensure \"minting\" diversity. This means that if more than K drop off, the network stalls. This should be solved by ensuring the signers are high-uptime machines and failing ones should be voted out in a timely fashion before too many failures occur (https://github.com/ethereum/EIPs/issues/225#issuecomment-284413381).\r\n * The proposal does not address \"legitimate\" spam, as in an attacker validly spending testnet ether to create junk, however without PoW mining, an attacker may not be able to obtain infinite ether to mount the attack in the first place. One possibility would be to have a faucet giving out ether based on GitHub (or whatever else) accounts in a limited fashion (e.g. 10 / day) (https://github.com/ethereum/EIPs/issues/225#issuecomment-284436932).\r\n * A suggestion was made to create checkpoint blocks for every epoch that contains a list of authorized signers at that point in time. This would allow light clients at a later point to say \"sync from here\" without needing to start from the genesis. This could be added to the extradata field as a prefix before the signature (https://github.com/ethereum/EIPs/issues/225#issuecomment-284725467)."},"comment":{"url":"https://api.github.com/repos/ethereum/EIPs/issues/comments/444467432","html_url":"https://github.com/ethereum/EIPs/issues/225#issuecomment-444467432","issue_url":"https://api.github.com/repos/ethereum/EIPs/issues/225","id":444467432,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0NDQ2NzQzMg==","user":{"login":"karalabe","id":129561,"node_id":"MDQ6VXNlcjEyOTU2MQ==","avatar_url":"https://avatars2.githubusercontent.com/u/129561?v=4","gravatar_id":"","url":"https://api.github.com/users/karalabe","html_url":"https://github.com/karalabe","followers_url":"https://api.github.com/users/karalabe/followers","following_url":"https://api.github.com/users/karalabe/following{/other_user}","gists_url":"https://api.github.com/users/karalabe/gists{/gist_id}","starred_url":"https://api.github.com/users/karalabe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/karalabe/subscriptions","organizations_url":"https://api.github.com/users/karalabe/orgs","repos_url":"https://api.github.com/users/karalabe/repos","events_url":"https://api.github.com/users/karalabe/events{/privacy}","received_events_url":"https://api.github.com/users/karalabe/received_events","type":"User","site_admin":false},"created_at":"2018-12-05T12:24:00Z","updated_at":"2018-12-05T12:24:00Z","author_association":"MEMBER","body":"@KaloNK Censorship doesn't work. If we were to introduce a mechanism to \"burn\" ether on demand, an attacker would just split its ether into millions of accounts. Since it's monopoly money, it doesn't matter that you pay some fees to distribute the funds. That would prevent cenzorship while also putting extra load on the network. TL:DR Censorship just makes the network worse, but doesn't solve the issue.\r\n\r\nAs for bringing new Ether into the system, that's what the prefunding is for. Make an insane amount, and put it behind a multisig if you want. Then you can control the release if you want to do so."}}
{"actor":{"display_login":"karalabe"}}