Merge branch 'dev' into pkg-the-pyspec
This commit is contained in:
commit
cd4e99f10e
4
setup.py
4
setup.py
|
@ -117,7 +117,7 @@ from dataclasses import (
|
||||||
from eth2spec.utils.ssz.ssz_impl import hash_tree_root
|
from eth2spec.utils.ssz.ssz_impl import hash_tree_root
|
||||||
from eth2spec.utils.ssz.ssz_typing import (
|
from eth2spec.utils.ssz.ssz_typing import (
|
||||||
View, boolean, Container, List, Vector, uint64, uint8, bit,
|
View, boolean, Container, List, Vector, uint64, uint8, bit,
|
||||||
ByteVector, ByteList, Bytes1, Bytes4, Bytes8, Bytes32, Bytes48, Bytes96, Bitlist, Bitvector,
|
ByteList, Bytes1, Bytes4, Bytes8, Bytes32, Bytes48, Bytes96, Bitlist, Bitvector,
|
||||||
)
|
)
|
||||||
from eth2spec.utils import bls
|
from eth2spec.utils import bls
|
||||||
|
|
||||||
|
@ -267,7 +267,7 @@ def dependency_order_ssz_objects(objects: Dict[str, str], custom_types: Dict[str
|
||||||
def combine_ssz_objects(old_objects: Dict[str, str], new_objects: Dict[str, str], custom_types) -> Dict[str, str]:
|
def combine_ssz_objects(old_objects: Dict[str, str], new_objects: Dict[str, str], custom_types) -> Dict[str, str]:
|
||||||
"""
|
"""
|
||||||
Takes in old spec and new spec ssz objects, combines them,
|
Takes in old spec and new spec ssz objects, combines them,
|
||||||
and returns the newer forks of the objects in dependency order.
|
and returns the newer versions of the objects in dependency order.
|
||||||
"""
|
"""
|
||||||
for key, value in new_objects.items():
|
for key, value in new_objects.items():
|
||||||
old_objects[key] = value
|
old_objects[key] = value
|
||||||
|
|
|
@ -189,7 +189,7 @@ def is_proposer(state: BeaconState,
|
||||||
|
|
||||||
*Note*: To see if a validator is assigned to propose during the slot, the beacon state must be in the epoch in question. At the epoch boundaries, the validator must run an epoch transition into the epoch to successfully check the proposal assignment of the first slot.
|
*Note*: To see if a validator is assigned to propose during the slot, the beacon state must be in the epoch in question. At the epoch boundaries, the validator must run an epoch transition into the epoch to successfully check the proposal assignment of the first slot.
|
||||||
|
|
||||||
*Note*: `BeaconBlock` proposal is distinct from beacon committee assignment, and in a given epoch each responsibility might occur at different a different slot.
|
*Note*: `BeaconBlock` proposal is distinct from beacon committee assignment, and in a given epoch each responsibility might occur at a different slot.
|
||||||
|
|
||||||
### Lookahead
|
### Lookahead
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,6 @@
|
||||||
- [`get_previous_slot`](#get_previous_slot)
|
- [`get_previous_slot`](#get_previous_slot)
|
||||||
- [`pack_compact_validator`](#pack_compact_validator)
|
- [`pack_compact_validator`](#pack_compact_validator)
|
||||||
- [`committee_to_compact_committee`](#committee_to_compact_committee)
|
- [`committee_to_compact_committee`](#committee_to_compact_committee)
|
||||||
- [`chunks_to_body_root`](#chunks_to_body_root)
|
|
||||||
- [`compute_shard_from_committee_index`](#compute_shard_from_committee_index)
|
- [`compute_shard_from_committee_index`](#compute_shard_from_committee_index)
|
||||||
- [Beacon state accessors](#beacon-state-accessors)
|
- [Beacon state accessors](#beacon-state-accessors)
|
||||||
- [`get_active_shard_count`](#get_active_shard_count)
|
- [`get_active_shard_count`](#get_active_shard_count)
|
||||||
|
@ -97,9 +96,8 @@ Configuration is not namespaced. Instead it is strictly an extension;
|
||||||
| `LIGHT_CLIENT_COMMITTEE_SIZE` | `2**7` (= 128) |
|
| `LIGHT_CLIENT_COMMITTEE_SIZE` | `2**7` (= 128) |
|
||||||
| `LIGHT_CLIENT_COMMITTEE_PERIOD` | `Epoch(2**8)` (= 256) | epochs | ~27 hours |
|
| `LIGHT_CLIENT_COMMITTEE_PERIOD` | `Epoch(2**8)` (= 256) | epochs | ~27 hours |
|
||||||
| `SHARD_COMMITTEE_PERIOD` | `Epoch(2**8)` (= 256) | epochs | ~27 hours |
|
| `SHARD_COMMITTEE_PERIOD` | `Epoch(2**8)` (= 256) | epochs | ~27 hours |
|
||||||
| `SHARD_BLOCK_CHUNK_SIZE` | `2**18` (= 262,144) | |
|
| `MAX_SHARD_BLOCK_SIZE` | `2**20` (= 1,048,576) | |
|
||||||
| `MAX_SHARD_BLOCK_CHUNKS` | `2**2` (= 4) | |
|
| `TARGET_SHARD_BLOCK_SIZE` | `2**18` (= 262,144) | |
|
||||||
| `TARGET_SHARD_BLOCK_SIZE` | `3 * 2**16` (= 196,608) | |
|
|
||||||
| `SHARD_BLOCK_OFFSETS` | `[1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233]` | |
|
| `SHARD_BLOCK_OFFSETS` | `[1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233]` | |
|
||||||
| `MAX_SHARD_BLOCKS_PER_ATTESTATION` | `len(SHARD_BLOCK_OFFSETS)` | |
|
| `MAX_SHARD_BLOCKS_PER_ATTESTATION` | `len(SHARD_BLOCK_OFFSETS)` | |
|
||||||
| `MAX_GASPRICE` | `Gwei(2**14)` (= 16,384) | Gwei | |
|
| `MAX_GASPRICE` | `Gwei(2**14)` (= 16,384) | Gwei | |
|
||||||
|
@ -297,7 +295,7 @@ class ShardBlockWrapper(Container):
|
||||||
shard_parent_root: Root
|
shard_parent_root: Root
|
||||||
beacon_parent_root: Root
|
beacon_parent_root: Root
|
||||||
slot: Slot
|
slot: Slot
|
||||||
body: ByteList[MAX_SHARD_BLOCK_CHUNKS * SHARD_BLOCK_CHUNK_SIZE]
|
body: ByteList[MAX_SHARD_BLOCK_SIZE]
|
||||||
signature: BLSSignature
|
signature: BLSSignature
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -330,7 +328,7 @@ class ShardTransition(Container):
|
||||||
# Shard block lengths
|
# Shard block lengths
|
||||||
shard_block_lengths: List[uint64, MAX_SHARD_BLOCKS_PER_ATTESTATION]
|
shard_block_lengths: List[uint64, MAX_SHARD_BLOCKS_PER_ATTESTATION]
|
||||||
# Shard data roots
|
# Shard data roots
|
||||||
shard_data_roots: List[List[Bytes32, MAX_SHARD_BLOCK_CHUNKS], MAX_SHARD_BLOCKS_PER_ATTESTATION]
|
shard_data_roots: List[Bytes32, MAX_SHARD_BLOCKS_PER_ATTESTATION]
|
||||||
# Intermediate shard states
|
# Intermediate shard states
|
||||||
shard_states: List[ShardState, MAX_SHARD_BLOCKS_PER_ATTESTATION]
|
shard_states: List[ShardState, MAX_SHARD_BLOCKS_PER_ATTESTATION]
|
||||||
# Proposer signature aggregate
|
# Proposer signature aggregate
|
||||||
|
@ -396,16 +394,6 @@ def committee_to_compact_committee(state: BeaconState, committee: Sequence[Valid
|
||||||
return CompactCommittee(pubkeys=pubkeys, compact_validators=compact_validators)
|
return CompactCommittee(pubkeys=pubkeys, compact_validators=compact_validators)
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `chunks_to_body_root`
|
|
||||||
|
|
||||||
```python
|
|
||||||
def chunks_to_body_root(chunks: List[Bytes32, MAX_SHARD_BLOCK_CHUNKS]) -> Root:
|
|
||||||
empty_chunk_root = hash_tree_root(ByteList[SHARD_BLOCK_CHUNK_SIZE]())
|
|
||||||
return hash_tree_root(Vector[Bytes32, MAX_SHARD_BLOCK_CHUNKS](
|
|
||||||
chunks + [empty_chunk_root] * (MAX_SHARD_BLOCK_CHUNKS - len(chunks))
|
|
||||||
))
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `compute_shard_from_committee_index`
|
#### `compute_shard_from_committee_index`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
@ -666,20 +654,18 @@ def apply_shard_transition(state: BeaconState, shard: Shard, transition: ShardTr
|
||||||
shard_parent_root=shard_parent_root,
|
shard_parent_root=shard_parent_root,
|
||||||
parent_hash=get_block_root_at_slot(state, get_previous_slot(state.slot)),
|
parent_hash=get_block_root_at_slot(state, get_previous_slot(state.slot)),
|
||||||
slot=offset_slots[i],
|
slot=offset_slots[i],
|
||||||
body_root=chunks_to_body_root(transition.shard_data_roots[i])
|
body_root=transition.shard_data_roots[i]
|
||||||
))
|
))
|
||||||
proposers.append(get_shard_proposer_index(state, shard, offset_slots[i]))
|
proposers.append(get_shard_proposer_index(state, shard, offset_slots[i]))
|
||||||
shard_parent_root = hash_tree_root(headers[-1])
|
shard_parent_root = hash_tree_root(headers[-1])
|
||||||
|
|
||||||
# Verify correct calculation of gas prices and slots and chunk roots
|
# Verify correct calculation of gas prices and slots
|
||||||
prev_gasprice = state.shard_states[shard].gasprice
|
prev_gasprice = state.shard_states[shard].gasprice
|
||||||
for i in range(len(offset_slots)):
|
for i in range(len(offset_slots)):
|
||||||
shard_state = transition.shard_states[i]
|
shard_state = transition.shard_states[i]
|
||||||
block_length = transition.shard_block_lengths[i]
|
block_length = transition.shard_block_lengths[i]
|
||||||
chunks = transition.shard_data_roots[i]
|
|
||||||
assert shard_state.gasprice == get_updated_gasprice(prev_gasprice, block_length)
|
assert shard_state.gasprice == get_updated_gasprice(prev_gasprice, block_length)
|
||||||
assert shard_state.slot == offset_slots[i]
|
assert shard_state.slot == offset_slots[i]
|
||||||
assert len(chunks) == block_length // SHARD_BLOCK_CHUNK_SIZE
|
|
||||||
prev_gasprice = shard_state.gasprice
|
prev_gasprice = shard_state.gasprice
|
||||||
|
|
||||||
pubkeys = [state.validators[proposer].pubkey for proposer in proposers]
|
pubkeys = [state.validators[proposer].pubkey for proposer in proposers]
|
||||||
|
@ -724,10 +710,7 @@ def process_crosslink_for_shard(state: BeaconState,
|
||||||
|
|
||||||
# Attestation <-> shard transition consistency
|
# Attestation <-> shard transition consistency
|
||||||
assert shard_transition_root == hash_tree_root(shard_transition)
|
assert shard_transition_root == hash_tree_root(shard_transition)
|
||||||
assert (
|
assert attestation.data.head_shard_root == shard_transition.shard_data_roots[-1]
|
||||||
attestation.data.head_shard_root
|
|
||||||
== chunks_to_body_root(shard_transition.shard_data_roots[-1])
|
|
||||||
)
|
|
||||||
|
|
||||||
# Apply transition
|
# Apply transition
|
||||||
apply_shard_transition(state, shard, shard_transition)
|
apply_shard_transition(state, shard, shard_transition)
|
||||||
|
@ -921,4 +904,3 @@ def process_light_client_committee_updates(state: BeaconState) -> None:
|
||||||
new_committee = get_light_client_committee(state, get_current_epoch(state) + LIGHT_CLIENT_COMMITTEE_PERIOD)
|
new_committee = get_light_client_committee(state, get_current_epoch(state) + LIGHT_CLIENT_COMMITTEE_PERIOD)
|
||||||
state.next_light_committee = committee_to_compact_committee(state, new_committee)
|
state.next_light_committee = committee_to_compact_committee(state, new_committee)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ class CustodySlashing(Container):
|
||||||
whistleblower_index: ValidatorIndex
|
whistleblower_index: ValidatorIndex
|
||||||
shard_transition: ShardTransition
|
shard_transition: ShardTransition
|
||||||
attestation: Attestation
|
attestation: Attestation
|
||||||
data: ByteList[MAX_SHARD_BLOCK_CHUNKS * SHARD_BLOCK_CHUNK_SIZE]
|
data: ByteList[MAX_SHARD_BLOCK_SIZE]
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `SignedCustodySlashing`
|
#### `SignedCustodySlashing`
|
||||||
|
@ -366,8 +366,7 @@ def process_custody_slashing(state: BeaconState, signed_custody_slashing: Signed
|
||||||
shard_transition = custody_slashing.shard_transition
|
shard_transition = custody_slashing.shard_transition
|
||||||
assert hash_tree_root(shard_transition) == attestation.shard_transition_root
|
assert hash_tree_root(shard_transition) == attestation.shard_transition_root
|
||||||
# Verify that the provided data matches the shard-transition
|
# Verify that the provided data matches the shard-transition
|
||||||
shard_chunk_roots = shard_transition.shard_data_roots[custody_slashing.data_index]
|
assert hash_tree_root(custody_slashing.data) == shard_transition.shard_data_roots[custody_slashing.data_index]
|
||||||
assert hash_tree_root(custody_slashing.data) == chunks_to_body_root(shard_chunk_roots)
|
|
||||||
|
|
||||||
# Verify existence and participation of claimed malefactor
|
# Verify existence and participation of claimed malefactor
|
||||||
attesters = get_attesting_indices(state, attestation.data, attestation.aggregation_bits)
|
attesters = get_attesting_indices(state, attestation.data, attestation.aggregation_bits)
|
||||||
|
|
|
@ -50,7 +50,7 @@ def shard_state_transition(shard: Shard,
|
||||||
pre_state: Root,
|
pre_state: Root,
|
||||||
previous_beacon_root: Root,
|
previous_beacon_root: Root,
|
||||||
proposer_pubkey: BLSPubkey,
|
proposer_pubkey: BLSPubkey,
|
||||||
block_data: ByteVector[MAX_SHARD_BLOCK_CHUNKS * SHARD_BLOCK_CHUNK_SIZE]) -> Root:
|
block_data: ByteList[MAX_SHARD_BLOCK_SIZE]) -> Root:
|
||||||
# We will add something more substantive in phase 2
|
# We will add something more substantive in phase 2
|
||||||
return hash(pre_state + hash_tree_root(previous_beacon_root) + hash_tree_root(block_data))
|
return hash(pre_state + hash_tree_root(previous_beacon_root) + hash_tree_root(block_data))
|
||||||
```
|
```
|
||||||
|
|
|
@ -33,7 +33,7 @@ This document describes the process of moving from Phase 0 to Phase 1 of Ethereu
|
||||||
Warning: this configuration is not definitive.
|
Warning: this configuration is not definitive.
|
||||||
|
|
||||||
| Name | Value |
|
| Name | Value |
|
||||||
| - | - | - |
|
| - | - |
|
||||||
| `PHASE_1_FORK_VERSION` | `Version('0x01000000')` |
|
| `PHASE_1_FORK_VERSION` | `Version('0x01000000')` |
|
||||||
| `INITIAL_ACTIVE_SHARDS` | `2**6` (= 64) |
|
| `INITIAL_ACTIVE_SHARDS` | `2**6` (= 64) |
|
||||||
| `INITIAL_GASPRICE` | `Gwei(10)` |
|
| `INITIAL_GASPRICE` | `Gwei(10)` |
|
||||||
|
|
|
@ -134,7 +134,7 @@ def case04_fast_aggregate_verify():
|
||||||
|
|
||||||
# Invalid signature -- extra pubkey
|
# Invalid signature -- extra pubkey
|
||||||
pubkeys_extra = pubkeys + [bls.G2ProofOfPossession.PrivToPub(PRIVKEYS[-1])]
|
pubkeys_extra = pubkeys + [bls.G2ProofOfPossession.PrivToPub(PRIVKEYS[-1])]
|
||||||
pubkeys_extra_serial = [encode_hex(pubkey) for pubkey in pubkeys]
|
pubkeys_extra_serial = [encode_hex(pubkey) for pubkey in pubkeys_extra]
|
||||||
full_name = f'{pubkeys_extra_serial}_{encode_hex(message)}_extra_pubkey'
|
full_name = f'{pubkeys_extra_serial}_{encode_hex(message)}_extra_pubkey'
|
||||||
yield f'fast_aggregate_verify_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', {
|
yield f'fast_aggregate_verify_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', {
|
||||||
'input': {
|
'input': {
|
||||||
|
|
Loading…
Reference in New Issue