Merge branch 'master' into rename_pow_to_deposit

This commit is contained in:
Hsiao-Wei Wang 2019-01-02 23:44:12 +08:00
commit dcaf510213
No known key found for this signature in database
GPG Key ID: 95B070122902DEA4
1 changed files with 47 additions and 48 deletions

View File

@ -54,7 +54,7 @@
- [Ethereum 1.0 deposit contract](#ethereum-10-deposit-contract) - [Ethereum 1.0 deposit contract](#ethereum-10-deposit-contract)
- [Deposit arguments](#deposit-arguments) - [Deposit arguments](#deposit-arguments)
- [Withdrawal credentials](#withdrawal-credentials) - [Withdrawal credentials](#withdrawal-credentials)
- [`Deposit` logs](#Deposit-logs) - [`Deposit` logs](#deposit-logs)
- [`ChainStart` log](#chainstart-log) - [`ChainStart` log](#chainstart-log)
- [Vyper code](#vyper-code) - [Vyper code](#vyper-code)
- [Beacon chain processing](#beacon-chain-processing) - [Beacon chain processing](#beacon-chain-processing)
@ -102,7 +102,7 @@
- [Attestations](#attestations-1) - [Attestations](#attestations-1)
- [Deposits](#deposits-1) - [Deposits](#deposits-1)
- [Exits](#exits-1) - [Exits](#exits-1)
- [Miscellaneous](#miscellaneous) - [Custody](#custody)
- [Per-epoch processing](#per-epoch-processing) - [Per-epoch processing](#per-epoch-processing)
- [Helpers](#helpers) - [Helpers](#helpers)
- [Deposit roots](#deposit-roots) - [Deposit roots](#deposit-roots)
@ -288,14 +288,14 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted
```python ```python
{ {
# Proof-of-custody indices (0 bits) # Validator indices with custody bit equal to 0
'aggregate_signature_poc_0_indices': '[uint24]', 'custody_bit_0_indices': ['uint24'],
# Proof-of-custody indices (1 bits) # Validator indices with custody bit equal to 1
'aggregate_signature_poc_1_indices': '[uint24]', 'custody_bit_1_indices': ['uint24'],
# Attestation data # Attestation data
'data': AttestationData, 'data': AttestationData,
# Aggregate signature # Aggregate signature
'aggregate_signature': '[uint384]', 'aggregate_signature': ['uint384'],
} }
``` ```
@ -309,7 +309,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted
'data': AttestationData, 'data': AttestationData,
# Attester participation bitfield # Attester participation bitfield
'participation_bitfield': 'bytes', 'participation_bitfield': 'bytes',
# Proof of custody bitfield # Custody bitfield
'custody_bitfield': 'bytes', 'custody_bitfield': 'bytes',
# BLS aggregate signature # BLS aggregate signature
'aggregate_signature': ['uint384'], 'aggregate_signature': ['uint384'],
@ -345,8 +345,8 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted
{ {
# Attestation data # Attestation data
data: AttestationData, data: AttestationData,
# Proof of custody bit # Custody bit
poc_bit: bool, custody_bit: bool,
} }
``` ```
@ -388,8 +388,8 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted
'withdrawal_credentials': 'hash32', 'withdrawal_credentials': 'hash32',
# Initial RANDAO commitment # Initial RANDAO commitment
'randao_commitment': 'hash32', 'randao_commitment': 'hash32',
# Initial proof of custody commitment # Initial custody commitment
'poc_commitment': 'hash32', 'custody_commitment': 'hash32',
# A BLS signature of this `DepositInput` # A BLS signature of this `DepositInput`
'proof_of_possession': ['uint384'], 'proof_of_possession': ['uint384'],
} }
@ -436,15 +436,15 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted
'proposer_slashings': [ProposerSlashing], 'proposer_slashings': [ProposerSlashing],
'casper_slashings': [CasperSlashing], 'casper_slashings': [CasperSlashing],
'attestations': [Attestation], 'attestations': [Attestation],
'poc_seed_changes': [ProofOfCustodySeedChange], 'custody_reseeds': [CustodyReseed],
'poc_challenges': [ProofOfCustodyChallenge], 'custody_challenges': [CustodyChallenge],
'poc_responses': [ProofOfCustodyResponse], 'custody_responses': [CustodyResponse],
'deposits': [Deposit], 'deposits': [Deposit],
'exits': [Exit], 'exits': [Exit],
} }
``` ```
`ProofOfCustodySeedChange`, `ProofOfCustodyChallenge`, and `ProofOfCustodyResponse` will be defined in phase 1; for now, put dummy classes as these lists will remain empty throughout phase 0. `CustodyReseed`, `CustodyChallenge`, and `CustodyResponse` will be defined in phase 1; for now, put dummy classes as these lists will remain empty throughout phase 0.
#### `ProposalSignedData` #### `ProposalSignedData`
@ -482,10 +482,8 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted
'latest_vdf_outputs': ['hash32'], 'latest_vdf_outputs': ['hash32'],
'shard_committees_at_slots': [[ShardCommittee]], 'shard_committees_at_slots': [[ShardCommittee]],
# Proof of custody # Custody challenges
# Placeholders for now; ProofOfCustodyChallenge is defined in phase 1, implementers can 'custody_challenges': [CustodyChallenge],
# put a dummy class in for now, as the list will remain empty throughout phase 0
'poc_challenges': [ProofOfCustodyChallenge],
# Finality # Finality
'previous_justified_slot': 'uint64', 'previous_justified_slot': 'uint64',
@ -524,11 +522,12 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted
'latest_status_change_slot': 'uint64', 'latest_status_change_slot': 'uint64',
# Exit counter when validator exited (or 0) # Exit counter when validator exited (or 0)
'exit_count': 'uint64', 'exit_count': 'uint64',
# Proof of custody commitment # Custody commitment
'poc_commitment': 'hash32', 'custody_commitment': 'hash32',
# Slot the proof of custody seed was last changed # Slot of latest custody reseed
'last_poc_change_slot': 'uint64', 'latest_custody_reseed_slot': 'uint64',
'second_last_poc_change_slot': 'uint64', # Slot of second-latest custody reseed
'penultimate_custody_reseed_slot': 'uint64',
} }
``` ```
@ -551,7 +550,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted
'shard': 'uint64', 'shard': 'uint64',
# Validator indices # Validator indices
'committee': ['uint24'], 'committee': ['uint24'],
# Total validator count (for proofs of custody) # Total validator count (for custody challenges)
'total_validator_count': 'uint64', 'total_validator_count': 'uint64',
} }
``` ```
@ -588,9 +587,9 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted
'data': AttestationData, 'data': AttestationData,
# Attester participation bitfield # Attester participation bitfield
'participation_bitfield': 'bytes', 'participation_bitfield': 'bytes',
# Proof of custody bitfield # Custody bitfield
'custody_bitfield': 'bytes', 'custody_bitfield': 'bytes',
# Slot in which it was included # Slot the attestation was included
'slot_included': 'uint64', 'slot_included': 'uint64',
} }
``` ```
@ -1050,13 +1049,13 @@ def get_domain(fork_data: ForkData,
```python ```python
def verify_slashable_vote_data(state: BeaconState, vote_data: SlashableVoteData) -> bool: def verify_slashable_vote_data(state: BeaconState, vote_data: SlashableVoteData) -> bool:
if len(vote_data.aggregate_signature_poc_0_indices) + len(vote_data.aggregate_signature_poc_1_indices) > MAX_CASPER_VOTES: if len(vote_data.custody_bit_0_indices) + len(vote_data.custody_bit_1_indices) > MAX_CASPER_VOTES:
return False return False
return bls_verify_multiple( return bls_verify_multiple(
pubkeys=[ pubkeys=[
aggregate_pubkey([state.validators[i].pubkey for i in vote_data.aggregate_signature_poc_0_indices]), aggregate_pubkey([state.validators[i].pubkey for i in vote_data.custody_bit_0_indices]),
aggregate_pubkey([state.validators[i].pubkey for i in vote_data.aggregate_signature_poc_1_indices]), aggregate_pubkey([state.validators[i].pubkey for i in vote_data.custody_bit_1_indices]),
], ],
messages=[ messages=[
hash_tree_root(AttestationDataAndCustodyBit(vote_data, False)), hash_tree_root(AttestationDataAndCustodyBit(vote_data, False)),
@ -1152,9 +1151,9 @@ A valid block with slot `INITIAL_SLOT_NUMBER` (a "genesis block") has the follow
proposer_slashings=[], proposer_slashings=[],
casper_slashings=[], casper_slashings=[],
attestations=[], attestations=[],
poc_seed_changes=[], custody_reseeds=[],
poc_challenges=[], custody_challenges=[],
poc_responses=[], custody_responses=[],
deposits=[], deposits=[],
exits=[], exits=[],
), ),
@ -1189,8 +1188,8 @@ def get_initial_beacon_state(initial_validator_deposits: List[Deposit],
latest_vdf_outputs=[ZERO_HASH for _ in range(LATEST_RANDAO_MIXES_LENGTH // EPOCH_LENGTH)], latest_vdf_outputs=[ZERO_HASH for _ in range(LATEST_RANDAO_MIXES_LENGTH // EPOCH_LENGTH)],
shard_committees_at_slots=[], shard_committees_at_slots=[],
# Proof of custody # Custody challenges
poc_challenges=[], custody_challenges=[],
# Finality # Finality
previous_justified_slot=INITIAL_SLOT_NUMBER, previous_justified_slot=INITIAL_SLOT_NUMBER,
@ -1219,7 +1218,7 @@ def get_initial_beacon_state(initial_validator_deposits: List[Deposit],
proof_of_possession=deposit.deposit_data.deposit_input.proof_of_possession, proof_of_possession=deposit.deposit_data.deposit_input.proof_of_possession,
withdrawal_credentials=deposit.deposit_data.deposit_input.withdrawal_credentials, withdrawal_credentials=deposit.deposit_data.deposit_input.withdrawal_credentials,
randao_commitment=deposit.deposit_data.deposit_input.randao_commitment, randao_commitment=deposit.deposit_data.deposit_input.randao_commitment,
poc_commitment=deposit.deposit_data.deposit_input.poc_commitment, custody_commitment=deposit.deposit_data.deposit_input.custody_commitment,
) )
if get_effective_balance(state, validator_index) == MAX_DEPOSIT * GWEI_PER_ETH: if get_effective_balance(state, validator_index) == MAX_DEPOSIT * GWEI_PER_ETH:
update_validator_status(state, validator_index, ACTIVE) update_validator_status(state, validator_index, ACTIVE)
@ -1251,12 +1250,12 @@ def validate_proof_of_possession(state: BeaconState,
proof_of_possession: bytes, proof_of_possession: bytes,
withdrawal_credentials: Hash32, withdrawal_credentials: Hash32,
randao_commitment: Hash32, randao_commitment: Hash32,
poc_commitment: Hash32) -> bool: custody_commitment: Hash32) -> bool:
proof_of_possession_data = DepositInput( proof_of_possession_data = DepositInput(
pubkey=pubkey, pubkey=pubkey,
withdrawal_credentials=withdrawal_credentials, withdrawal_credentials=withdrawal_credentials,
randao_commitment=randao_commitment, randao_commitment=randao_commitment,
poc_commitment=poc_commitment, custody_commitment=custody_commitment,
proof_of_possession=EMPTY_SIGNATURE, proof_of_possession=EMPTY_SIGNATURE,
) )
@ -1281,7 +1280,7 @@ def process_deposit(state: BeaconState,
proof_of_possession: bytes, proof_of_possession: bytes,
withdrawal_credentials: Hash32, withdrawal_credentials: Hash32,
randao_commitment: Hash32, randao_commitment: Hash32,
poc_commitment: Hash32) -> int: custody_commitment: Hash32) -> int:
""" """
Process a deposit from Ethereum 1.0. Process a deposit from Ethereum 1.0.
Note that this function mutates ``state``. Note that this function mutates ``state``.
@ -1293,7 +1292,7 @@ def process_deposit(state: BeaconState,
proof_of_possession, proof_of_possession,
withdrawal_credentials, withdrawal_credentials,
randao_commitment, randao_commitment,
poc_commitment, custody_commitment,
) )
validator_pubkeys = [v.pubkey for v in state.validator_registry] validator_pubkeys = [v.pubkey for v in state.validator_registry]
@ -1308,9 +1307,9 @@ def process_deposit(state: BeaconState,
status=PENDING_ACTIVATION, status=PENDING_ACTIVATION,
latest_status_change_slot=state.slot, latest_status_change_slot=state.slot,
exit_count=0, exit_count=0,
poc_commitment=poc_commitment, custody_commitment=custody_commitment,
last_poc_change_slot=0, latest_custody_reseed_slot=INITIAL_SLOT_NUMBER,
second_last_poc_change_slot=0, penultimate_custody_reseed_slot=INITIAL_SLOT_NUMBER,
) )
index = min_empty_validator_index(state.validator_registry, state.validator_balances, state.slot) index = min_empty_validator_index(state.validator_registry, state.validator_balances, state.slot)
@ -1496,7 +1495,7 @@ For each `casper_slashing` in `block.body.casper_slashings`:
* Let `slashable_vote_data_1 = casper_slashing.slashable_vote_data_1`. * Let `slashable_vote_data_1 = casper_slashing.slashable_vote_data_1`.
* Let `slashable_vote_data_2 = casper_slashing.slashable_vote_data_2`. * Let `slashable_vote_data_2 = casper_slashing.slashable_vote_data_2`.
* Let `indices(slashable_vote_data) = slashable_vote_data.aggregate_signature_poc_0_indices + slashable_vote_data.aggregate_signature_poc_1_indices`. * Let `indices(slashable_vote_data) = slashable_vote_data.custody_bit_0_indices + slashable_vote_data.custody_bit_1_indices`.
* Let `intersection = [x for x in indices(slashable_vote_data_1) if x in indices(slashable_vote_data_2)]`. * Let `intersection = [x for x in indices(slashable_vote_data_1) if x in indices(slashable_vote_data_2)]`.
* Verify that `len(intersection) >= 1`. * Verify that `len(intersection) >= 1`.
* Verify that `slashable_vote_data_1.data != slashable_vote_data_2.data`. * Verify that `slashable_vote_data_1.data != slashable_vote_data_2.data`.
@ -1556,7 +1555,7 @@ process_deposit(
proof_of_possession=deposit.deposit_data.deposit_input.proof_of_possession, proof_of_possession=deposit.deposit_data.deposit_input.proof_of_possession,
withdrawal_credentials=deposit.deposit_data.deposit_input.withdrawal_credentials, withdrawal_credentials=deposit.deposit_data.deposit_input.withdrawal_credentials,
randao_commitment=deposit.deposit_data.deposit_input.randao_commitment, randao_commitment=deposit.deposit_data.deposit_input.randao_commitment,
poc_commitment=deposit.deposit_data.deposit_input.poc_commitment, custody_commitment=deposit.deposit_data.deposit_input.custody_commitment,
) )
``` ```
@ -1572,9 +1571,9 @@ For each `exit` in `block.body.exits`:
* Verify that `bls_verify(pubkey=validator.pubkey, message=ZERO_HASH, signature=exit.signature, domain=get_domain(state.fork_data, exit.slot, DOMAIN_EXIT))`. * Verify that `bls_verify(pubkey=validator.pubkey, message=ZERO_HASH, signature=exit.signature, domain=get_domain(state.fork_data, exit.slot, DOMAIN_EXIT))`.
* Run `update_validator_status(state, validator_index, new_status=ACTIVE_PENDING_EXIT)`. * Run `update_validator_status(state, validator_index, new_status=ACTIVE_PENDING_EXIT)`.
#### Miscellaneous #### Custody
[TO BE REMOVED IN PHASE 1] Verify that `len(block.body.poc_seed_changes) == len(block.body.poc_challenges) == len(block.body.poc_responses) == 0`. [TO BE REMOVED IN PHASE 1] Verify that `len(block.body.custody_reseeds) == len(block.body.custody_challenges) == len(block.body.custody_responses) == 0`.
## Per-epoch processing ## Per-epoch processing