mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-02-20 22:38:11 +00:00
Test deposit top-up with inconsistent withdrawal credentials (#1133)
* Simplify deposits * Avoid divisions by zero Possible fix to avoid four cases of divisions by zero: * `return state.validator_registry[index].effective_balance // adjusted_quotient // BASE_REWARDS_PER_EPOCH` * `rewards[index] += get_base_reward(state, index) * attesting_balance // total_balance` * `validator.effective_balance * min(total_penalties * 3, total_balance) // total_balance` * `rewards[index] += base_reward * attesting_balance // committee_balance` See also #1107. * fix deposit test for new index handling * tests: deposit with inconsistent withdrawal credentials * Update README.md * Update 0_beacon-chain.md * Fix linter errors * Update test_process_deposit.py * fix deposit test * fix lint
This commit is contained in:
parent
0fd29f7fe9
commit
cc5b172da3
@ -94,6 +94,22 @@ def test_invalid_sig_top_up(state):
|
||||
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):
|
||||
validator_index = len(state.validator_registry)
|
||||
@ -122,6 +138,7 @@ def test_wrong_deposit_for_deposit_count(state):
|
||||
pubkey_1,
|
||||
privkey_1,
|
||||
spec.MAX_EFFECTIVE_BALANCE,
|
||||
withdrawal_credentials=b'\x00'*32,
|
||||
signed=True,
|
||||
)
|
||||
deposit_count_1 = len(deposit_data_leaves)
|
||||
@ -136,6 +153,7 @@ def test_wrong_deposit_for_deposit_count(state):
|
||||
pubkey_2,
|
||||
privkey_2,
|
||||
spec.MAX_EFFECTIVE_BALANCE,
|
||||
withdrawal_credentials=b'\x00'*32,
|
||||
signed=True,
|
||||
)
|
||||
|
||||
|
@ -8,11 +8,10 @@ from eth2spec.utils.merkle_minimal import calc_merkle_tree_from_leaves, get_merk
|
||||
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:
|
||||
@ -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)
|
||||
@ -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.
|
||||
"""
|
||||
@ -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
|
||||
)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user