Skip to content

Commit

Permalink
tests: deposit with inconsistent withdrawal credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsproul committed May 29, 2019
1 parent 5a64b4a commit cb2061c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ def test_invalid_sig_top_up(state):
# invalid signatures, in top-ups, are allowed!
yield from run_deposit_processing(state, deposit, validator_index, valid=True, effective=True)

@spec_state_test
def test_invalid_withdrawal_credentials_top_up(state):
validator_index = 0
amount = spec.MAX_EFFECTIVE_BALANCE // 4
withdrawal_credentials = spec.BLS_WITHDRAWAL_PREFIX_BYTE + spec.hash(b"junk")[1:]
deposit = prepare_state_and_deposit(state, validator_index, amount,
withdrawal_credentials=withdrawal_credentials)

# inconsistent withdrawal credentials, in top-ups, are allowed!
yield from run_deposit_processing(state, deposit, validator_index, valid=True, effective=True)


@spec_state_test
def test_wrong_index(state):
Expand Down
16 changes: 11 additions & 5 deletions test_libs/pyspec/eth2spec/test/helpers/deposits.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
from eth2spec.utils.minimal_ssz import signing_root


def build_deposit_data(state, pubkey, privkey, amount, signed=False):
def build_deposit_data(state, pubkey, privkey, amount, withdrawal_credentials, signed=False):
deposit_data = DepositData(
pubkey=pubkey,
# insecurely use pubkey as withdrawal key as well
withdrawal_credentials=spec.BLS_WITHDRAWAL_PREFIX_BYTE + spec.hash(pubkey)[1:],
withdrawal_credentials=withdrawal_credentials,
amount=amount,
)
if signed:
Expand All @@ -37,8 +36,9 @@ def build_deposit(state,
pubkey,
privkey,
amount,
withdrawal_credentials,
signed):
deposit_data = build_deposit_data(state, pubkey, privkey, amount, signed)
deposit_data = build_deposit_data(state, pubkey, privkey, amount, withdrawal_credentials, signed)

item = deposit_data.hash_tree_root()
index = len(deposit_data_leaves)
Expand All @@ -57,7 +57,7 @@ def build_deposit(state,
return deposit, root, deposit_data_leaves


def prepare_state_and_deposit(state, validator_index, amount, signed=False):
def prepare_state_and_deposit(state, validator_index, amount, withdrawal_credentials=None, signed=False):
"""
Prepare the state for the deposit, and create a deposit for the given validator, depositing the given amount.
"""
Expand All @@ -67,12 +67,18 @@ def prepare_state_and_deposit(state, validator_index, amount, signed=False):

pubkey = pubkeys[validator_index]
privkey = privkeys[validator_index]

# insecurely use pubkey as withdrawal key if no credentials provided
if withdrawal_credentials is None:
withdrawal_credentials = spec.BLS_WITHDRAWAL_PREFIX_BYTE + spec.hash(pubkey)[1:]

deposit, root, deposit_data_leaves = build_deposit(
state,
deposit_data_leaves,
pubkey,
privkey,
amount,
withdrawal_credentials,
signed
)

Expand Down

0 comments on commit cb2061c

Please sign in to comment.