From 1ea887c964557aaaa0e56a7dd9efade613bbdaf1 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 13 Dec 2018 23:36:57 +0800 Subject: [PATCH] Deposits: define `DepositData` and rename `DepositParameters` to `DepositInput` (#310) --- specs/core/0_beacon-chain.md | 54 +++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 28b08d119..2b23aa013 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -32,7 +32,8 @@ - [`AttestationData`](#attestationdata) - [Deposits](#deposits) - [`Deposit`](#deposit) - - [`DepositParameters`](#depositparameters) + - [`DepositData`](#depositdata) + - [`DepositInput`](#depositinput) - [Exits](#exits) - [`Exit`](#exit) - [Beacon chain blocks](#beacon-chain-blocks) @@ -344,18 +345,24 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted # Merkle tree index 'merkle_tree_index': 'uint64', # Deposit data - 'deposit_data': { - # Deposit parameters - 'deposit_parameters': DepositParameters, - # Value in Gwei - 'value': 'uint64', - # Timestamp from deposit contract - 'timestamp': 'uint64', - }, + 'deposit_data': DepositData, } ``` -##### `DepositParameters` +##### `DepositData` + +```python +{ + # Deposit parameters + 'deposit_input': DepositInput, + # Value in Gwei + 'value': 'uint64', + # Timestamp from deposit contract + 'timestamp': 'uint64', +} +``` + +##### `DepositInput` ```python { @@ -579,7 +586,7 @@ The initial deployment phases of Ethereum 2.0 are implemented without consensus ### Deposit arguments -The deposit contract has a single `deposit` function which takes as argument a SimpleSerialize'd `DepositParameters`. One of the `DepositParameters` fields is `withdrawal_credentials` which must satisfy: +The deposit contract has a single `deposit` function which takes as argument a SimpleSerialize'd `DepositInput`. One of the `DepositInput` fields is `withdrawal_credentials` which must satisfy: * `withdrawal_credentials[:1] == BLS_WITHDRAWAL_PREFIX_BYTE` * `withdrawal_credentials[1:] == hash(withdrawal_pubkey)[1:]` where `withdrawal_pubkey` is a BLS pubkey @@ -619,14 +626,14 @@ full_deposit_count: uint256 @payable @public -def deposit(deposit_parameters: bytes[2048]): +def deposit(deposit_input: bytes[2048]): assert msg.value >= as_wei_value(MIN_DEPOSIT, "ether") assert msg.value <= as_wei_value(MAX_DEPOSIT, "ether") index: uint256 = self.deposit_count + 2**DEPOSIT_CONTRACT_TREE_DEPTH msg_gwei_bytes8: bytes[8] = slice(concat("", convert(msg.value / GWEI_PER_ETH, bytes32)), start=24, len=8) timestamp_bytes8: bytes[8] = slice(concat("", convert(block.timestamp, bytes32)), start=24, len=8) - deposit_data: bytes[2064] = concat(msg_gwei_bytes8, timestamp_bytes8, deposit_parameters) + deposit_data: bytes[2064] = concat(msg_gwei_bytes8, timestamp_bytes8, deposit_input) log.Eth1Deposit(self.receipt_tree[1], deposit_data, self.deposit_count) @@ -1116,7 +1123,8 @@ def get_initial_beacon_state(initial_validator_deposits: List[Deposit], latest_block_roots=[ZERO_HASH for _ in range(LATEST_BLOCK_ROOTS_LENGTH)], latest_penalized_exit_balances=[], latest_attestations=[], - batched_block_roots=[] + batched_block_roots=[], + # PoW receipt root processed_pow_receipt_root=processed_pow_receipt_root, candidate_pow_receipt_roots=[], @@ -1126,11 +1134,11 @@ def get_initial_beacon_state(initial_validator_deposits: List[Deposit], for deposit in initial_validator_deposits: validator_index = process_deposit( state=state, - pubkey=deposit.deposit_data.deposit_parameters.pubkey, + pubkey=deposit.deposit_data.deposit_input.pubkey, deposit=deposit.deposit_data.value, - proof_of_possession=deposit.deposit_data.deposit_parameters.proof_of_possession, - withdrawal_credentials=deposit.deposit_data.deposit_parameters.withdrawal_credentials, - randao_commitment=deposit.deposit_data.deposit_parameters.randao_commitment + proof_of_possession=deposit.deposit_data.deposit_input.proof_of_possession, + withdrawal_credentials=deposit.deposit_data.deposit_input.withdrawal_credentials, + randao_commitment=deposit.deposit_data.deposit_input.randao_commitment ) if state.validator_registry[index].balance >= MAX_DEPOSIT * GWEI_PER_ETH: update_validator_status(state, index, ACTIVE) @@ -1418,7 +1426,7 @@ Verify that `len(block.body.deposits) <= MAX_DEPOSITS`. For each `deposit` in `block.body.deposits`: -* Let `serialized_deposit_data` be the serialized form of `deposit.deposit_data`. It should be the `DepositParameters` followed by 8 bytes for `deposit_data.value` and 8 bytes for `deposit_data.timestamp`. That is, it should match `deposit_data` in the [Ethereum 1.0 deposit contract](#ethereum-10-chain-deposit-contract) of which the hash was placed into the Merkle tree. +* Let `serialized_deposit_data` be the serialized form of `deposit.deposit_data`. It should be the `DepositInput` followed by 8 bytes for `deposit_data.value` and 8 bytes for `deposit_data.timestamp`. 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. * Use the following procedure to verify `deposit.merkle_branch`, setting `leaf=serialized_deposit_data`, `depth=DEPOSIT_CONTRACT_TREE_DEPTH` and `root=state.processed_pow_receipt_root`: ```python @@ -1438,11 +1446,11 @@ def verify_merkle_branch(leaf: Hash32, branch: [Hash32], depth: int, index: int, ```python process_deposit( state=state, - pubkey=deposit.deposit_data.deposit_parameters.pubkey, + pubkey=deposit.deposit_data.deposit_input.pubkey, deposit=deposit.deposit_data.value, - proof_of_possession=deposit.deposit_data.deposit_parameters.proof_of_possession, - withdrawal_credentials=deposit.deposit_data.deposit_parameters.withdrawal_credentials, - randao_commitment=deposit.deposit_data.deposit_parameters.randao_commitment + proof_of_possession=deposit.deposit_data.deposit_input.proof_of_possession, + withdrawal_credentials=deposit.deposit_data.deposit_input.withdrawal_credentials, + randao_commitment=deposit.deposit_data.deposit_input.randao_commitment ) ```