Skip to content

Commit

Permalink
Merge pull request #1122 from ethereum/JustinDrake-patch-13
Browse files Browse the repository at this point in the history
Simplify deposits
  • Loading branch information
djrtwo committed May 30, 2019
2 parents 2aea4b9 + f0314be commit 0fd29f7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 9 deletions.
5 changes: 1 addition & 4 deletions specs/core/0_beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -1761,12 +1759,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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import eth2spec.phase0.spec as spec
from eth2spec.phase0.spec import process_deposit
from eth2spec.test.context import spec_state_test, expect_assertion_error, always_bls
from eth2spec.test.helpers.deposits import prepare_state_and_deposit, sign_deposit_data
from eth2spec.test.helpers.deposits import (
build_deposit,
prepare_state_and_deposit,
sign_deposit_data,
)
from eth2spec.test.helpers.state import get_balance
from eth2spec.test.helpers.keys import privkeys
from eth2spec.test.helpers.keys import privkeys, pubkeys


def run_deposit_processing(state, deposit, validator_index, valid=True, effective=True):
Expand All @@ -18,9 +22,6 @@ def run_deposit_processing(state, deposit, validator_index, valid=True, effectiv
pre_balance = 0
if validator_index < pre_validator_count:
pre_balance = get_balance(state, validator_index)
else:
# if it is a new validator, it should be right at the end of the current registry.
assert validator_index == pre_validator_count

yield 'pre', state
yield 'deposit', deposit
Expand Down Expand Up @@ -107,6 +108,44 @@ def test_wrong_index(state):
yield from run_deposit_processing(state, deposit, validator_index, valid=False)


@spec_state_test
def test_wrong_deposit_for_deposit_count(state):
deposit_data_leaves = [spec.ZERO_HASH] * len(state.validator_registry)

# 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(
state,
deposit_data_leaves,
pubkey_1,
privkey_1,
spec.MAX_EFFECTIVE_BALANCE,
signed=True,
)
deposit_count_1 = len(deposit_data_leaves)

# 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(
state,
deposit_data_leaves,
pubkey_2,
privkey_2,
spec.MAX_EFFECTIVE_BALANCE,
signed=True,
)

# state has root for deposit_2 but is at deposit_count for deposit_1
state.latest_eth1_data.deposit_root = root_2
state.latest_eth1_data.deposit_count = deposit_count_1

yield from run_deposit_processing(state, deposit_2, index_2, valid=False)


# TODO: test invalid signature


Expand Down

0 comments on commit 0fd29f7

Please sign in to comment.