From 16928c85bb32ccaff020fd5389f956c63baa7388 Mon Sep 17 00:00:00 2001 From: Justin Date: Thu, 4 Oct 2018 11:21:33 +0100 Subject: [PATCH 1/2] Clean up codes, flags, types This includes: * Optimised values (e.g. `PENALIZED` now fits in a single byte) * More consistent values (e.g. the flags start at 0) * Added types for specials --- specs/beacon-chain.md | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/specs/beacon-chain.md b/specs/beacon-chain.md index 5437e32ad..26c7bd4a5 100644 --- a/specs/beacon-chain.md +++ b/specs/beacon-chain.md @@ -51,18 +51,20 @@ The primary source of load on the beacon chain are "attestations". Attestations * The `BASE_REWARD_QUOTIENT` constant is the per-slot interest rate assuming all validators are participating, assuming total deposits of 1 ETH. It corresponds to ~3.88% annual interest assuming 10 million participating ETH. * At most `1/MAX_VALIDATOR_CHURN_QUOTIENT` of the validators can change during each dynasty. -**Status codes** +**Codes, flags, types** -| Status code | Value | -| - | :-: | -| `PENDING_LOG_IN` | `0` | -| `LOGGED_IN` | `1` | -| `PENDING_EXIT` | `2` | -| `PENDING_WITHDRAW` | `3` | -| `WITHDRAWN` | `4` | -| `PENALIZED` | `128` | -| `ENTRY` | `1` | -| `EXIT` | `2` | +| Name | Value | Category | +| - | :-: | :-: | +| `PENDING_LOG_IN` | `0` | code | +| `LOGGED_IN` | `1` | code | +| `PENDING_EXIT` | `2` | code | +| `PENDING_WITHDRAW` | `3` | code | +| `WITHDRAWN` | `4` | code | +| `PENALIZED` | `127` | code | +| `ENTRY` | `0` | flag | +| `EXIT` | `1` | flag | +| `LOGOUT` | `0` | type | +| `CASPER_SLASHING` | `1` | type | ### PoW chain registration contract @@ -525,8 +527,8 @@ Let `committees` be the set of committees processed and `time_since_last_confirm For each `SpecialObject` `obj` in `active_state.pending_specials`: -* **[covers logouts]**: If `obj.type == 0`, interpret `data[0]` as a validator index as an `int32` and `data[1]` as a signature. If `BLSVerify(pubkey=validators[data[0]].pubkey, msg=hash("bye bye"), sig=data[1])`, and `validators[i].status == LOGGED_IN`, set `validators[i].status = PENDING_EXIT` and `validators[i].exit_slot = current_slot` -* **[covers `NO_DBL_VOTE`, `NO_SURROUND`, `NO_DBL_PROPOSE` slashing conditions]:** If `obj.type == 1`, interpret `data[0]` as a list of concatenated `int32` values where each value represents an index into `validators`, `data[1]` as the data being signed and `data[2]` as an aggregate signature. Interpret `data[3:6]` similarly. Verify that both signatures are valid, that the two signatures are signing distinct data, and that they are either signing the same slot number, or that one surrounds the other (ie. `source1 < source2 < target2 < target1`). Let `inds` be the list of indices in both signatures; verify that its length is at least 1. For each validator index `v` in `inds`, set their end dynasty to equal the current dynasty plus 1, and if its `status` does not equal `PENALIZED`, then: +* **[covers logouts]**: If `obj.type == LOGOUT`, interpret `data[0]` as a validator index as an `int32` and `data[1]` as a signature. If `BLSVerify(pubkey=validators[data[0]].pubkey, msg=hash("bye bye"), sig=data[1])`, and `validators[i].status == LOGGED_IN`, set `validators[i].status = PENDING_EXIT` and `validators[i].exit_slot = current_slot` +* **[covers `NO_DBL_VOTE`, `NO_SURROUND`, `NO_DBL_PROPOSE` slashing conditions]:** If `obj.type == CASPER_SLASHING`, interpret `data[0]` as a list of concatenated `int32` values where each value represents an index into `validators`, `data[1]` as the data being signed and `data[2]` as an aggregate signature. Interpret `data[3:6]` similarly. Verify that both signatures are valid, that the two signatures are signing distinct data, and that they are either signing the same slot number, or that one surrounds the other (ie. `source1 < source2 < target2 < target1`). Let `inds` be the list of indices in both signatures; verify that its length is at least 1. For each validator index `v` in `inds`, set their end dynasty to equal the current dynasty plus 1, and if its `status` does not equal `PENALIZED`, then: 1. Set its `exit_slot` to equal the current `slot` 2. Set its `status` to `PENALIZED` From 5306c1e728db72fb819b6d6a19ad987e714594c0 Mon Sep 17 00:00:00 2001 From: Justin Date: Thu, 4 Oct 2018 14:16:31 +0100 Subject: [PATCH 2/2] Update beacon-chain.md --- specs/beacon-chain.md | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/specs/beacon-chain.md b/specs/beacon-chain.md index 26c7bd4a5..57d992c16 100644 --- a/specs/beacon-chain.md +++ b/specs/beacon-chain.md @@ -1,7 +1,6 @@ # Ethereum 2.0 spec—Casper and sharding ###### tags: `spec`, `eth2.0`, `casper`, `sharding` -###### spec version: 2.2 (October 2018) **NOTICE**: This document is a work-in-progress for researchers and implementers. It reflects recent spec changes and takes precedence over the [Python proof-of-concept implementation](https://github.com/ethereum/beacon_chain). @@ -44,6 +43,7 @@ The primary source of load on the beacon chain are "attestations". Attestations | `WITHDRAWAL_PERIOD` | 2**19 (= 524,288) | slots | ~97 days | | `BASE_REWARD_QUOTIENT` | 2**15 (= 32,768) | — | | `MAX_VALIDATOR_CHURN_QUOTIENT` | 2**5 (= 32) | — | +| `LOGOUT_MESSAGE` | `"LOGOUT"` | — | **Notes** @@ -51,20 +51,30 @@ The primary source of load on the beacon chain are "attestations". Attestations * The `BASE_REWARD_QUOTIENT` constant is the per-slot interest rate assuming all validators are participating, assuming total deposits of 1 ETH. It corresponds to ~3.88% annual interest assuming 10 million participating ETH. * At most `1/MAX_VALIDATOR_CHURN_QUOTIENT` of the validators can change during each dynasty. -**Codes, flags, types** +**Validator status codes** -| Name | Value | Category | -| - | :-: | :-: | -| `PENDING_LOG_IN` | `0` | code | -| `LOGGED_IN` | `1` | code | -| `PENDING_EXIT` | `2` | code | -| `PENDING_WITHDRAW` | `3` | code | -| `WITHDRAWN` | `4` | code | -| `PENALIZED` | `127` | code | -| `ENTRY` | `0` | flag | -| `EXIT` | `1` | flag | -| `LOGOUT` | `0` | type | -| `CASPER_SLASHING` | `1` | type | +| Name | Value | +| - | :-: | +| `PENDING_LOG_IN` | `0` | +| `LOGGED_IN` | `1` | +| `PENDING_EXIT` | `2` | +| `PENDING_WITHDRAW` | `3` | +| `WITHDRAWN` | `4` | +| `PENALIZED` | `127` | + +**Special record types** + +| Name | Value | +| - | :-: | +| `LOGOUT` | `0` | +| `CASPER_SLASHING` | `1` | + +**Validator set delta flags** + +| Name | Value | +| - | :-: | +| `ENTRY` | `0` | +| `EXIT` | `1` | ### PoW chain registration contract @@ -527,8 +537,8 @@ Let `committees` be the set of committees processed and `time_since_last_confirm For each `SpecialObject` `obj` in `active_state.pending_specials`: -* **[covers logouts]**: If `obj.type == LOGOUT`, interpret `data[0]` as a validator index as an `int32` and `data[1]` as a signature. If `BLSVerify(pubkey=validators[data[0]].pubkey, msg=hash("bye bye"), sig=data[1])`, and `validators[i].status == LOGGED_IN`, set `validators[i].status = PENDING_EXIT` and `validators[i].exit_slot = current_slot` -* **[covers `NO_DBL_VOTE`, `NO_SURROUND`, `NO_DBL_PROPOSE` slashing conditions]:** If `obj.type == CASPER_SLASHING`, interpret `data[0]` as a list of concatenated `int32` values where each value represents an index into `validators`, `data[1]` as the data being signed and `data[2]` as an aggregate signature. Interpret `data[3:6]` similarly. Verify that both signatures are valid, that the two signatures are signing distinct data, and that they are either signing the same slot number, or that one surrounds the other (ie. `source1 < source2 < target2 < target1`). Let `inds` be the list of indices in both signatures; verify that its length is at least 1. For each validator index `v` in `inds`, set their end dynasty to equal the current dynasty plus 1, and if its `status` does not equal `PENALIZED`, then: +* **[covers logouts]**: If `obj.type == LOGOUT`, interpret `data[0]` as a validator index as an `int32` and `data[1]` as a signature. If `BLSVerify(pubkey=validators[data[0]].pubkey, msg=hash(LOGOUT_MESSAGE), sig=data[1])`, and `validators[i].status == LOGGED_IN`, set `validators[i].status = PENDING_EXIT` and `validators[i].exit_slot = current_slot` +* **[covers `NO_DBL_VOTE`, `NO_SURROUND`, `NO_DBL_PROPOSE` slashing conditions]:** If `obj.type == CASPER_SLASHING`, interpret `data[0]` as a list of concatenated `int32` values where each value represents an index into `validators`, `data[1]` as the data being signed and `data[2]` as an aggregate signature. Interpret `data[3:6]` similarly. Verify that both signatures are valid, that the two signatures are signing distinct data, and that they are either signing the same slot number, or that one surrounds the other (ie. `source1 < source2 < target2 < target1`). Let `indices` be the list of indices in both signatures; verify that its length is at least 1. For each validator index `v` in `indices`, set their end dynasty to equal the current dynasty plus 1, and if its `status` does not equal `PENALIZED`, then: 1. Set its `exit_slot` to equal the current `slot` 2. Set its `status` to `PENALIZED`