mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-02-11 18:16:56 +00:00
Merge branch 'dev' into vbuterin-patch-7
This commit is contained in:
commit
5ac30fdf77
@ -77,6 +77,7 @@
|
|||||||
- [`generate_seed`](#generate_seed)
|
- [`generate_seed`](#generate_seed)
|
||||||
- [`get_beacon_proposer_index`](#get_beacon_proposer_index)
|
- [`get_beacon_proposer_index`](#get_beacon_proposer_index)
|
||||||
- [`merkle_root`](#merkle_root)
|
- [`merkle_root`](#merkle_root)
|
||||||
|
- [`verify_merkle_branch`](#verify_merkle_branch)
|
||||||
- [`get_attestation_participants`](#get_attestation_participants)
|
- [`get_attestation_participants`](#get_attestation_participants)
|
||||||
- [`is_power_of_two`](#is_power_of_two)
|
- [`is_power_of_two`](#is_power_of_two)
|
||||||
- [`int_to_bytes1`, `int_to_bytes2`, ...](#int_to_bytes1-int_to_bytes2-)
|
- [`int_to_bytes1`, `int_to_bytes2`, ...](#int_to_bytes1-int_to_bytes2-)
|
||||||
@ -386,7 +387,7 @@ The following data structures are defined as [SimpleSerialize (SSZ)](https://git
|
|||||||
```python
|
```python
|
||||||
{
|
{
|
||||||
# Branch in the deposit tree
|
# Branch in the deposit tree
|
||||||
'branch': ['bytes32'],
|
'proof': ['bytes32'],
|
||||||
# Index in the deposit tree
|
# Index in the deposit tree
|
||||||
'index': 'uint64',
|
'index': 'uint64',
|
||||||
# Data
|
# Data
|
||||||
@ -983,11 +984,19 @@ def generate_seed(state: BeaconState,
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
def get_beacon_proposer_index(state: BeaconState,
|
def get_beacon_proposer_index(state: BeaconState,
|
||||||
slot: Slot) -> ValidatorIndex:
|
slot: Slot,
|
||||||
|
registry_change: bool=False) -> ValidatorIndex:
|
||||||
"""
|
"""
|
||||||
Return the beacon proposer index for the ``slot``.
|
Return the beacon proposer index for the ``slot``.
|
||||||
"""
|
"""
|
||||||
first_committee, _ = get_crosslink_committees_at_slot(state, slot)[0]
|
epoch = slot_to_epoch(slot)
|
||||||
|
current_epoch = get_current_epoch(state)
|
||||||
|
previous_epoch = get_previous_epoch(state)
|
||||||
|
next_epoch = current_epoch + 1
|
||||||
|
|
||||||
|
assert previous_epoch <= epoch <= next_epoch
|
||||||
|
|
||||||
|
first_committee, _ = get_crosslink_committees_at_slot(state, slot, registry_change)[0]
|
||||||
return first_committee[slot % len(first_committee)]
|
return first_committee[slot % len(first_committee)]
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -1005,6 +1014,23 @@ def merkle_root(values: List[Bytes32]) -> Bytes32:
|
|||||||
return o[1]
|
return o[1]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `verify_merkle_branch`
|
||||||
|
|
||||||
|
```python
|
||||||
|
def verify_merkle_branch(leaf: Bytes32, proof: List[Bytes32], depth: int, index: int, root: Bytes32) -> bool:
|
||||||
|
"""
|
||||||
|
Verify that the given ``leaf`` is on the merkle branch ``proof``
|
||||||
|
starting with the given ``root``.
|
||||||
|
"""
|
||||||
|
value = leaf
|
||||||
|
for i in range(depth):
|
||||||
|
if index // (2**i) % 2:
|
||||||
|
value = hash(proof[i] + value)
|
||||||
|
else:
|
||||||
|
value = hash(value + proof[i])
|
||||||
|
return value == root
|
||||||
|
```
|
||||||
|
|
||||||
### `get_attestation_participants`
|
### `get_attestation_participants`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
@ -1067,7 +1093,7 @@ def get_effective_balance(state: BeaconState, index: ValidatorIndex) -> Gwei:
|
|||||||
```python
|
```python
|
||||||
def get_total_balance(state: BeaconState, validators: List[ValidatorIndex]) -> Gwei:
|
def get_total_balance(state: BeaconState, validators: List[ValidatorIndex]) -> Gwei:
|
||||||
"""
|
"""
|
||||||
Return the combined effective balance of an array of validators.
|
Return the combined effective balance of an array of ``validators``.
|
||||||
"""
|
"""
|
||||||
return sum([get_effective_balance(state, i) for i in validators])
|
return sum([get_effective_balance(state, i) for i in validators])
|
||||||
```
|
```
|
||||||
@ -1251,6 +1277,31 @@ def process_deposit(state: BeaconState, deposit: Deposit) -> None:
|
|||||||
"""
|
"""
|
||||||
deposit_input = deposit.deposit_data.deposit_input
|
deposit_input = deposit.deposit_data.deposit_input
|
||||||
|
|
||||||
|
# Should equal 8 bytes for deposit_data.amount +
|
||||||
|
# 8 bytes for deposit_data.timestamp +
|
||||||
|
# 176 bytes for deposit_data.deposit_input
|
||||||
|
# It should match the deposit_data in the eth1.0 deposit contract
|
||||||
|
serialized_deposit_data = serialize(deposit.deposit_data)
|
||||||
|
# Deposits must be processed in order
|
||||||
|
assert deposit.index == state.deposit_index
|
||||||
|
|
||||||
|
# Verify the Merkle branch
|
||||||
|
merkle_branch_is_valid = verify_merkle_branch(
|
||||||
|
leaf=hash(serialized_deposit_data),
|
||||||
|
proof=deposit.proof,
|
||||||
|
depth=DEPOSIT_CONTRACT_TREE_DEPTH,
|
||||||
|
index=deposit.index,
|
||||||
|
root=state.latest_eth1_data.deposit_root,
|
||||||
|
)
|
||||||
|
assert merkle_branch_is_valid
|
||||||
|
|
||||||
|
# Increment the next deposit index we are expecting. Note that this
|
||||||
|
# needs to be done here because while the deposit contract will never
|
||||||
|
# create an invalid Merkle branch, it may admit an invalid deposit
|
||||||
|
# object, and we need to be able to skip over it
|
||||||
|
state.deposit_index += 1
|
||||||
|
|
||||||
|
# Verify the proof of possession
|
||||||
proof_is_valid = bls_verify(
|
proof_is_valid = bls_verify(
|
||||||
pubkey=deposit_input.pubkey,
|
pubkey=deposit_input.pubkey,
|
||||||
message_hash=signed_root(deposit_input, "proof_of_possession"),
|
message_hash=signed_root(deposit_input, "proof_of_possession"),
|
||||||
@ -1506,7 +1557,7 @@ def get_genesis_beacon_state(genesis_validator_deposits: List[Deposit],
|
|||||||
# Ethereum 1.0 chain data
|
# Ethereum 1.0 chain data
|
||||||
latest_eth1_data=genesis_eth1_data,
|
latest_eth1_data=genesis_eth1_data,
|
||||||
eth1_data_votes=[],
|
eth1_data_votes=[],
|
||||||
deposit_index=len(genesis_validator_deposits)
|
deposit_index=0,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Process genesis deposits
|
# Process genesis deposits
|
||||||
@ -1844,35 +1895,7 @@ def process_attestation(state: BeaconState, attestation: Attestation) -> None:
|
|||||||
|
|
||||||
Verify that `len(block.body.deposits) <= MAX_DEPOSITS`.
|
Verify that `len(block.body.deposits) <= MAX_DEPOSITS`.
|
||||||
|
|
||||||
[TODO: update the call to `verify_merkle_branch` below if it needs to change after we process deposits in order]
|
For each `deposit` in `block.body.deposits`, run `process_deposit(state, deposit)`.
|
||||||
|
|
||||||
For each `deposit` in `block.body.deposits`:
|
|
||||||
|
|
||||||
* Let `serialized_deposit_data` be the serialized form of `deposit.deposit_data`. It should be 8 bytes for `deposit_data.amount` followed by 8 bytes for `deposit_data.timestamp` and then the `DepositInput` bytes. That is, it should match `deposit_data` in the [Ethereum 1.0 deposit contract](#ethereum-10-deposit-contract) of which the hash was placed into the Merkle tree.
|
|
||||||
* Verify that `deposit.index == state.deposit_index`.
|
|
||||||
* Verify that `verify_merkle_branch(hash(serialized_deposit_data), deposit.branch, DEPOSIT_CONTRACT_TREE_DEPTH, deposit.index, state.latest_eth1_data.deposit_root)` is `True`.
|
|
||||||
|
|
||||||
```python
|
|
||||||
def verify_merkle_branch(leaf: Bytes32, branch: List[Bytes32], depth: int, index: int, root: Bytes32) -> bool:
|
|
||||||
"""
|
|
||||||
Verify that the given ``leaf`` is on the merkle branch ``branch``.
|
|
||||||
"""
|
|
||||||
value = leaf
|
|
||||||
for i in range(depth):
|
|
||||||
if index // (2**i) % 2:
|
|
||||||
value = hash(branch[i] + value)
|
|
||||||
else:
|
|
||||||
value = hash(value + branch[i])
|
|
||||||
return value == root
|
|
||||||
```
|
|
||||||
|
|
||||||
* Run the following:
|
|
||||||
|
|
||||||
```python
|
|
||||||
process_deposit(state, deposit)
|
|
||||||
```
|
|
||||||
|
|
||||||
* Set `state.deposit_index += 1`.
|
|
||||||
|
|
||||||
##### Voluntary exits
|
##### Voluntary exits
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ __NOTICE__: This document is a work-in-progress for researchers and implementers
|
|||||||
- [Aggregation bitfield](#aggregation-bitfield)
|
- [Aggregation bitfield](#aggregation-bitfield)
|
||||||
- [Custody bitfield](#custody-bitfield)
|
- [Custody bitfield](#custody-bitfield)
|
||||||
- [Aggregate signature](#aggregate-signature)
|
- [Aggregate signature](#aggregate-signature)
|
||||||
- [Validator assigments](#validator-assignments)
|
- [Validator assignments](#validator-assignments)
|
||||||
- [Lookahead](#lookahead)
|
- [Lookahead](#lookahead)
|
||||||
- [How to avoid slashing](#how-to-avoid-slashing)
|
- [How to avoid slashing](#how-to-avoid-slashing)
|
||||||
- [Proposer slashing](#proposer-slashing)
|
- [Proposer slashing](#proposer-slashing)
|
||||||
@ -371,8 +371,7 @@ def get_committee_assignment(
|
|||||||
if len(selected_committees) > 0:
|
if len(selected_committees) > 0:
|
||||||
validators = selected_committees[0][0]
|
validators = selected_committees[0][0]
|
||||||
shard = selected_committees[0][1]
|
shard = selected_committees[0][1]
|
||||||
first_committee_at_slot = crosslink_committees[0][0] # List[ValidatorIndex]
|
is_proposer = validator_index == get_beacon_proposer_index(state, slot, registry_change=registry_change)
|
||||||
is_proposer = first_committee_at_slot[slot % len(first_committee_at_slot)] == validator_index
|
|
||||||
|
|
||||||
assignment = (validators, shard, slot, is_proposer)
|
assignment = (validators, shard, slot, is_proposer)
|
||||||
return assignment
|
return assignment
|
||||||
|
Loading…
x
Reference in New Issue
Block a user