From 20e31b29300b4ca89ebe779597eb56bbe0506f7b Mon Sep 17 00:00:00 2001 From: Vitalik Buterin Date: Tue, 9 Oct 2018 19:26:03 -0400 Subject: [PATCH 1/8] Remove multiple slots per committee option --- specs/beacon-chain.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/specs/beacon-chain.md b/specs/beacon-chain.md index 12817748c..e0d65f899 100644 --- a/specs/beacon-chain.md +++ b/specs/beacon-chain.md @@ -348,25 +348,25 @@ def split(lst, N): return [lst[len(lst)*i//N: len(lst)*(i+1)//N] for i in range(N)] ``` +A helper method for readability: + +```python +def clamp(minval, x, maxval): + return minval if x < minval else maxval if x > maxval else x +``` + Now, our combined helper method: ```python def get_new_shuffling(seed, validators, crosslinking_start_shard): active_validators = get_active_validator_indices(validators) - if len(active_validators) >= CYCLE_LENGTH * MIN_COMMITTEE_SIZE: - committees_per_slot = min(len(active_validators) // CYCLE_LENGTH // (MIN_COMMITTEE_SIZE * 2) + 1, SHARD_COUNT // CYCLE_LENGTH) - slots_per_committee = 1 - else: - committees_per_slot = 1 - slots_per_committee = 1 - while len(active_validators) * slots_per_committee < CYCLE_LENGTH * MIN_COMMITTEE_SIZE \ - and slots_per_committee < CYCLE_LENGTH: - slots_per_committee *= 2 + committees_per_slot = clamp(1, + len(active_validators) // CYCLE_LENGTH // (MIN_COMMITTEE_SIZE * 2) + 1, + SHARD_COUNT // CYCLE_LENGTH) o = [] for i, slot_indices in enumerate(split(shuffle(active_validators, seed), CYCLE_LENGTH)): shard_indices = split(slot_indices, committees_per_slot) - shard_start = crosslinking_start_shard + \ - i * committees_per_slot // slots_per_committee + shard_start = crosslinking_start_shard + i * committees_per_slot o.append([ShardAndCommittee( shard = (shard_start + j) % SHARD_COUNT, committee = indices From 1c25917622d201ff3afd0005bf991555beaf50f0 Mon Sep 17 00:00:00 2001 From: vbuterin Date: Thu, 11 Oct 2018 09:51:35 -0400 Subject: [PATCH 2/8] Add bool to simple serialize --- specs/simple-serialize.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/specs/simple-serialize.md b/specs/simple-serialize.md index 5e666706d..678f95906 100644 --- a/specs/simple-serialize.md +++ b/specs/simple-serialize.md @@ -81,6 +81,20 @@ buffer_size = int_size / 8 return value.to_bytes(buffer_size, 'big') ``` +#### bool + +Convert directly to a single 0x00 or 0x01 byte. + +| Check to perform | Code | +|:------------------|:---------------------------| +| Value is boolean | ``value in (True, False)`` | + +```python +assert(value in (True, False)) +return b'\x01' if value is True else b'\x00' +``` + + #### Address The address should already come as a hash/byte format. Ensure that length is @@ -237,6 +251,15 @@ new_index = current_index + int_size return int.from_bytes(rawbytes[current_index:current_index+int_size], 'big'), new_index ``` +#### Bool + +Return True if 0x01, False if 0x00. + +```python +assert rawbytes in (b'\x00', b'\x01') +return True if rawbytes == b'\x01' else False +``` + #### Address Return the 20 bytes. From 2d3b13ccf4edc94956f5e85b7cb9eb645707b476 Mon Sep 17 00:00:00 2001 From: vbuterin Date: Fri, 12 Oct 2018 00:45:58 -0400 Subject: [PATCH 3/8] Add version to logout message Resolves https://github.com/ethereum/eth2.0-specs/issues/57 --- specs/beacon-chain.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/specs/beacon-chain.md b/specs/beacon-chain.md index d5ca0c648..36b7df3cb 100644 --- a/specs/beacon-chain.md +++ b/specs/beacon-chain.md @@ -664,7 +664,8 @@ In addition, validators with `status == PENALIZED` lose `B // reward_quotient + For each `SpecialRecord` `obj` in `active_state.pending_specials`: -* **[covers logouts]**: If `obj.kind == 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 == ACTIVE`, set `validators[i].status = PENDING_EXIT` and `validators[i].exit_slot = current_slot` +* **[covers logouts]**: If `obj.kind == 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 + bytes8(version)), sig=data[1])`, where `version = pre_fork_version if slot < fork_slot_number else post_fork_version`, returns True, and `validators[i].status == ACTIVE`, 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.kind == 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`, if its `status` does not equal `PENALIZED`, then: 1. Set its `exit_slot` to equal the current `slot` From 73854e85985879d2148bf0bb110dec8ad3fc4ee2 Mon Sep 17 00:00:00 2001 From: James Ray <16969914+jamesray1@users.noreply.github.com> Date: Fri, 12 Oct 2018 19:22:12 +1100 Subject: [PATCH 4/8] Re-add removed rationale for min. committee size --- specs/beacon-chain.md | 1 + 1 file changed, 1 insertion(+) diff --git a/specs/beacon-chain.md b/specs/beacon-chain.md index d5ca0c648..76d4fbf22 100644 --- a/specs/beacon-chain.md +++ b/specs/beacon-chain.md @@ -46,6 +46,7 @@ The primary source of load on the beacon chain are "attestations". Attestations **Notes** +* See a recommended `MIN_COMMITTEE_SIZE` of 111 here https://vitalik.ca/files/Ithaca201807_Sharding.pdf). * The `SQRT_E_DROP_TIME` constant is the amount of time it takes for the quadratic leak to cut deposits of non-participating validators by ~39.4%. * 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 validator set change. From 0dc597a11ce39f79a0d87b0399a33ccf4316e9bf Mon Sep 17 00:00:00 2001 From: Yutaro Mori Date: Sun, 14 Oct 2018 12:31:06 +0900 Subject: [PATCH 5/8] Remove remaining usage of dynasty --- specs/beacon-chain.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/specs/beacon-chain.md b/specs/beacon-chain.md index 36b7df3cb..d4fe05a8c 100644 --- a/specs/beacon-chain.md +++ b/specs/beacon-chain.md @@ -492,9 +492,6 @@ def on_startup(initial_validator_entries: List[Any]) -> Tuple[CrystallizedState, for i in range(SHARD_COUNT) ] crystallized_state = CrystallizedState( - dynasty=1, - dynasty_seed=bytes([0] * 32), # stub - dynasty_start_slot=0, validators=validators, crosslinks=crosslinks, last_state_recalculation_slot=0, From eb93cef16d5e22d33590bf1875df60a3a3d8dc4e Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Sun, 14 Oct 2018 08:03:08 -0500 Subject: [PATCH 6/8] add `validator_change_slot` to startup init vars --- specs/beacon-chain.md | 1 + 1 file changed, 1 insertion(+) diff --git a/specs/beacon-chain.md b/specs/beacon-chain.md index d4fe05a8c..a4ce066da 100644 --- a/specs/beacon-chain.md +++ b/specs/beacon-chain.md @@ -492,6 +492,7 @@ def on_startup(initial_validator_entries: List[Any]) -> Tuple[CrystallizedState, for i in range(SHARD_COUNT) ] crystallized_state = CrystallizedState( + validator_set_change_slot=0, validators=validators, crosslinks=crosslinks, last_state_recalculation_slot=0, From cdabb4b2058ca65afce1077c181d6b1a36d61041 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Sun, 14 Oct 2018 08:32:10 -0500 Subject: [PATCH 7/8] remove extra def of clamp --- specs/beacon-chain.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/specs/beacon-chain.md b/specs/beacon-chain.md index d458ec085..cf285d1ae 100644 --- a/specs/beacon-chain.md +++ b/specs/beacon-chain.md @@ -378,8 +378,6 @@ def clamp(minval: int, maxval: int, x: int) -> int: return maxval else: return x -def clamp(minval, maxval, x): - return minval if x < minval else maxval if x > maxval else x ``` Now, our combined helper method: From cf28f1a784f6a9a8c8e411e34dbf8bb613023093 Mon Sep 17 00:00:00 2001 From: Mikerah Date: Sun, 14 Oct 2018 16:29:47 -0400 Subject: [PATCH 8/8] Adding first completed version of ssz in JS to list of ssz implementations --- specs/simple-serialize.md | 1 + 1 file changed, 1 insertion(+) diff --git a/specs/simple-serialize.md b/specs/simple-serialize.md index 678f95906..be58a68dd 100644 --- a/specs/simple-serialize.md +++ b/specs/simple-serialize.md @@ -369,3 +369,4 @@ return deserialized_list, new_index | Rust | [ https://github.com/sigp/lighthouse/tree/master/beacon_chain/utils/ssz ](https://github.com/sigp/lighthouse/tree/master/beacon_chain/utils/ssz) | Lighthouse (Rust Ethereum 2.0 Node) maintained SSZ. | | Nim | [ https://github.com/status-im/nim-beacon-chain/blob/master/beacon_chain/ssz.nim ](https://github.com/status-im/nim-beacon-chain/blob/master/beacon_chain/ssz.nim) | Nim Implementation maintained SSZ. | | Rust | [ https://github.com/paritytech/shasper/tree/master/util/ssz ](https://github.com/paritytech/shasper/tree/master/util/ssz) | Shasper implementation of SSZ maintained by ParityTech. | +| Javascript | [ https://github.com/ChainSafeSystems/ssz-js/blob/master/src/index.js ](https://github.com/ChainSafeSystems/ssz-js/blob/master/src/index.js) | Javascript Implementation maintained SSZ |