fix deposit domain: forks are ignored for deposit validity, deposits are always accepted, if coming from the correct contract(s).

This commit is contained in:
protolambda 2019-05-06 22:06:00 +02:00
parent 5c2bca4a0d
commit 3a309155aa
No known key found for this signature in database
GPG Key ID: EC89FDBB2B4C7623
2 changed files with 5 additions and 3 deletions

View File

@ -966,7 +966,8 @@ def get_domain(state: BeaconState,
"""
epoch = get_current_epoch(state) if message_epoch is None else message_epoch
fork_version = state.fork.previous_version if epoch < state.fork.epoch else state.fork.current_version
return bytes_to_int(fork_version + int_to_bytes4(domain_type))
# fork version is on the big-endian side: when signing using only the type (e.g. deposits), the type can be passed directly.
return bytes_to_int(int_to_bytes4(domain_type) + fork_version)
```
### `get_bitfield_bit`
@ -1766,7 +1767,8 @@ def process_deposit(state: BeaconState, deposit: Deposit) -> None:
validator_pubkeys = [v.pubkey for v in state.validator_registry]
if pubkey not in validator_pubkeys:
# Verify the deposit signature (proof of possession)
if not bls_verify(pubkey, signing_root(deposit.data), deposit.data.signature, get_domain(state, DOMAIN_DEPOSIT)):
# Note: deposits are valid regardless of fork version, hence the type is passed directly as domain.
if not bls_verify(pubkey, signing_root(deposit.data), deposit.data.signature, DOMAIN_DEPOSIT):
return
# Add validator and balance entries

View File

@ -103,7 +103,7 @@ To submit a deposit:
* Pack the validator's [initialization parameters](#initialization) into `deposit_data`, a [`DepositData`](../core/0_beacon-chain.md#depositdata) SSZ object.
* Let `amount` be the amount in Gwei to be deposited by the validator where `MIN_DEPOSIT_AMOUNT <= amount <= MAX_EFFECTIVE_BALANCE`.
* Set `deposit_data.amount = amount`.
* Let `signature` be the result of `bls_sign` of the `signing_root(deposit_data)` with `domain=DOMAIN_DEPOSIT`.
* Let `signature` be the result of `bls_sign` of the `signing_root(deposit_data)` with `domain=DOMAIN_DEPOSIT`. (Deposits are valid regardless of fork version, hence the type is passed directly as domain.)
* Send a transaction on the Ethereum 1.0 chain to `DEPOSIT_CONTRACT_ADDRESS` executing `def deposit(pubkey: bytes[48], withdrawal_credentials: bytes[32], signature: bytes[96])` along with a deposit of `amount` Gwei.
*Note*: Deposits made for the same `pubkey` are treated as for the same validator. A singular `Validator` will be added to `state.validator_registry` with each additional deposit amount added to the validator's balance. A validator can only be activated when total deposits for the validator pubkey meet or exceed `MAX_EFFECTIVE_BALANCE`.