From d805fb508446c8b9a6a0299cf5ac585b2597362d Mon Sep 17 00:00:00 2001 From: Justin Date: Sat, 25 May 2019 00:35:17 +0300 Subject: [PATCH 1/2] Simplify deposits --- specs/core/0_beacon-chain.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 60f774e9a8..48a686735d 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -471,8 +471,6 @@ The types are defined topologically to aid in facilitating an executable version { # Branch in the deposit tree 'proof': ['bytes32', DEPOSIT_CONTRACT_TREE_DEPTH], - # Index in the deposit tree - 'index': 'uint64', # Data 'data': DepositData, } @@ -1763,12 +1761,11 @@ def process_deposit(state: BeaconState, deposit: Deposit) -> None: leaf=hash_tree_root(deposit.data), proof=deposit.proof, depth=DEPOSIT_CONTRACT_TREE_DEPTH, - index=deposit.index, + index=state.deposit_index, root=state.latest_eth1_data.deposit_root, ) # Deposits must be processed in order - assert deposit.index == state.deposit_index state.deposit_index += 1 pubkey = deposit.data.pubkey From 47f3df6d0a6296f950289057f3082c6c95d907be Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Mon, 27 May 2019 16:40:00 -0600 Subject: [PATCH 2/2] fix deposit test for new index handling --- .../block_processing/test_process_deposit.py | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/test_libs/pyspec/tests/block_processing/test_process_deposit.py b/test_libs/pyspec/tests/block_processing/test_process_deposit.py index bbfb390efb..62b058a707 100644 --- a/test_libs/pyspec/tests/block_processing/test_process_deposit.py +++ b/test_libs/pyspec/tests/block_processing/test_process_deposit.py @@ -83,33 +83,45 @@ def test_success_top_up(state): return pre_state, deposit, post_state -def test_wrong_index(state): +def test_wrong_deposit_for_deposit_count(state): pre_state = deepcopy(state) deposit_data_leaves = [ZERO_HASH] * len(pre_state.validator_registry) - index = len(deposit_data_leaves) - pubkey = pubkeys[index] - privkey = privkeys[index] - deposit, root, deposit_data_leaves = build_deposit( + # build root for deposit_1 + index_1 = len(deposit_data_leaves) + pubkey_1 = pubkeys[index_1] + privkey_1 = privkeys[index_1] + deposit_1, root_1, deposit_data_leaves = build_deposit( pre_state, deposit_data_leaves, - pubkey, - privkey, + pubkey_1, + privkey_1, spec.MAX_EFFECTIVE_BALANCE, ) + deposit_count_1 = len(deposit_data_leaves) - # mess up deposit_index - deposit.index = pre_state.deposit_index + 1 + # build root for deposit_2 + index_2 = len(deposit_data_leaves) + pubkey_2 = pubkeys[index_2] + privkey_2 = privkeys[index_2] + deposit_2, root_2, deposit_data_leaves = build_deposit( + pre_state, + deposit_data_leaves, + pubkey_2, + privkey_2, + spec.MAX_EFFECTIVE_BALANCE, + ) - pre_state.latest_eth1_data.deposit_root = root - pre_state.latest_eth1_data.deposit_count = len(deposit_data_leaves) + # state has root for deposit_2 but is at deposit_count for deposit_1 + pre_state.latest_eth1_data.deposit_root = root_2 + pre_state.latest_eth1_data.deposit_count = deposit_count_1 post_state = deepcopy(pre_state) with pytest.raises(AssertionError): - process_deposit(post_state, deposit) + process_deposit(post_state, deposit_2) - return pre_state, deposit, None + return pre_state, deposit_2, None def test_bad_merkle_proof(state):