Enables transferes of BAL > 32 ETH

This commit is contained in:
Carl Beekhuizen 2019-04-16 16:16:13 +10:00
parent acd172f4d1
commit ed28515a95
4 changed files with 19 additions and 18 deletions

View File

@ -32,7 +32,7 @@ def test_success(state):
deposit_data_leaves,
pubkey,
privkey,
spec.MAX_DEPOSIT_AMOUNT,
spec.MAX_EFFECTIVE_BALANCE,
)
pre_state.latest_eth1_data.deposit_root = root
@ -45,7 +45,7 @@ def test_success(state):
assert len(post_state.validator_registry) == len(state.validator_registry) + 1
assert len(post_state.balances) == len(state.balances) + 1
assert post_state.validator_registry[index].pubkey == pubkeys[index]
assert get_balance(post_state, index) == spec.MAX_DEPOSIT_AMOUNT
assert get_balance(post_state, index) == spec.MAX_EFFECTIVE_BALANCE
assert post_state.deposit_index == post_state.latest_eth1_data.deposit_count
return pre_state, deposit, post_state
@ -56,7 +56,7 @@ def test_success_top_up(state):
deposit_data_leaves = [ZERO_HASH] * len(pre_state.validator_registry)
validator_index = 0
amount = spec.MAX_DEPOSIT_AMOUNT // 4
amount = spec.MAX_EFFECTIVE_BALANCE // 4
pubkey = pubkeys[validator_index]
privkey = privkeys[validator_index]
deposit, root, deposit_data_leaves = build_deposit(
@ -95,7 +95,7 @@ def test_wrong_index(state):
deposit_data_leaves,
pubkey,
privkey,
spec.MAX_DEPOSIT_AMOUNT,
spec.MAX_EFFECTIVE_BALANCE,
)
# mess up deposit_index
@ -124,7 +124,7 @@ def test_bad_merkle_proof(state):
deposit_data_leaves,
pubkey,
privkey,
spec.MAX_DEPOSIT_AMOUNT,
spec.MAX_EFFECTIVE_BALANCE,
)
# mess up merkle branch

View File

@ -58,7 +58,7 @@ def create_mock_genesis_validator_deposits(num_validators, deposit_data_leaves=N
pubkey=pubkey,
# insecurely use pubkey as withdrawal key as well
withdrawal_credentials=spec.BLS_WITHDRAWAL_PREFIX_BYTE + hash(pubkey)[1:],
amount=spec.MAX_DEPOSIT_AMOUNT,
amount=spec.MAX_EFFECTIVE_BALANCE,
proof_of_possession=proof_of_possession,
)
item = hash(deposit_data.serialize())

View File

@ -177,7 +177,7 @@ def test_deposit_in_block(state):
index = len(test_deposit_data_leaves)
pubkey = pubkeys[index]
privkey = privkeys[index]
deposit_data = build_deposit_data(pre_state, pubkey, privkey, spec.MAX_DEPOSIT_AMOUNT)
deposit_data = build_deposit_data(pre_state, pubkey, privkey, spec.MAX_EFFECTIVE_BALANCE)
item = hash(deposit_data.serialize())
test_deposit_data_leaves.append(item)
@ -201,7 +201,7 @@ def test_deposit_in_block(state):
state_transition(post_state, block)
assert len(post_state.validator_registry) == len(state.validator_registry) + 1
assert len(post_state.balances) == len(state.balances) + 1
assert get_balance(post_state, index) == spec.MAX_DEPOSIT_AMOUNT
assert get_balance(post_state, index) == spec.MAX_EFFECTIVE_BALANCE
assert post_state.validator_registry[index].pubkey == pubkeys[index]
return pre_state, [block], post_state
@ -212,7 +212,7 @@ def test_deposit_top_up(state):
test_deposit_data_leaves = [ZERO_HASH] * len(pre_state.validator_registry)
validator_index = 0
amount = spec.MAX_DEPOSIT_AMOUNT // 4
amount = spec.MAX_EFFECTIVE_BALANCE // 4
pubkey = pubkeys[validator_index]
privkey = privkeys[validator_index]
deposit_data = build_deposit_data(pre_state, pubkey, privkey, amount)

View File

@ -201,7 +201,7 @@ These configurations are updated for releases, but may be out of sync during `de
| Name | Value | Unit |
| - | - | :-: |
| `MIN_DEPOSIT_AMOUNT` | `2**0 * 10**9` (= 1,000,000,000) | Gwei |
| `MAX_DEPOSIT_AMOUNT` | `2**5 * 10**9` (= 32,000,000,000) | Gwei |
| `MAX_EFFECTIVE_BALANCE` | `2**5 * 10**9` (= 32,000,000,000) | Gwei |
| `EJECTION_BALANCE` | `2**4 * 10**9` (= 16,000,000,000) | Gwei |
| `HIGH_BALANCE_INCREMENT` | `2**0 * 10**9` (= 1,000,000,000) | Gwei |
@ -1002,7 +1002,7 @@ def get_beacon_proposer_index(state: BeaconState,
int_to_bytes8(i // 32)
)[i % 32]
candidate = first_committee[(current_epoch + i) % len(first_committee)]
if get_effective_balance(state, candidate) * 256 > MAX_DEPOSIT_AMOUNT * rand_byte:
if get_effective_balance(state, candidate) * 256 > MAX_EFFECTIVE_BALANCE * rand_byte:
return candidate
i += 1
```
@ -1081,7 +1081,7 @@ def get_effective_balance(state: BeaconState, index: ValidatorIndex) -> Gwei:
"""
Return the effective balance (also known as "balance at stake") for a validator with the given ``index``.
"""
return min(get_balance(state, index), MAX_DEPOSIT_AMOUNT)
return min(get_balance(state, index), MAX_EFFECTIVE_BALANCE)
```
### `get_total_balance`
@ -1373,7 +1373,7 @@ The private key corresponding to `withdrawal_pubkey` will be required to initiat
### `Deposit` logs
Every Ethereum 1.0 deposit, of size between `MIN_DEPOSIT_AMOUNT` and `MAX_DEPOSIT_AMOUNT`, emits a `Deposit` log for consumption by the beacon chain. The deposit contract does little validation, pushing most of the validator onboarding logic to the beacon chain. In particular, the proof of possession (a BLS12 signature) is not verified by the deposit contract.
Every Ethereum 1.0 deposit, of size greater than `MIN_DEPOSIT_AMOUNT`, emits a `Deposit` log for consumption by the beacon chain. The deposit contract does little validation, pushing most of the validator onboarding logic to the beacon chain. In particular, the proof of possession (a BLS12 signature) is not verified by the deposit contract.
### `Eth2Genesis` log
@ -1395,7 +1395,7 @@ For convenience, we provide the interface to the contract here:
* `__init__()`: initializes the contract
* `get_deposit_root() -> bytes32`: returns the current root of the deposit tree
* `deposit(bytes[512])`: adds a deposit instance to the deposit tree, incorporating the input argument and the value transferred in the given call. Note: the amount of value transferred *must* be within `MIN_DEPOSIT_AMOUNT` and `MAX_DEPOSIT_AMOUNT`, inclusive. Each of these constants are specified in units of Gwei.
* `deposit(bytes[512])`: adds a deposit instance to the deposit tree, incorporating the input argument and the value transferred in the given call. Note: the amount of value transferred *must* be greater than `MIN_DEPOSIT_AMOUNT` inclusive. Each of these constants are specified in units of Gwei.
## On genesis
@ -1495,7 +1495,7 @@ def get_genesis_beacon_state(genesis_validator_deposits: List[Deposit],
# Process genesis activations
for validator_index in range(len(state.validator_registry)):
if get_effective_balance(state, validator_index) >= MAX_DEPOSIT_AMOUNT:
if get_effective_balance(state, validator_index) >= MAX_EFFECTIVE_BALANCE:
activate_validator(state, validator_index, is_genesis=True)
genesis_active_index_root = hash_tree_root(get_active_validator_indices(state, GENESIS_EPOCH))
@ -1936,7 +1936,7 @@ def process_balance_driven_status_transitions(state: BeaconState) -> None:
"""
for index, validator in enumerate(state.validator_registry):
balance = get_balance(state, index)
if validator.activation_eligibility_epoch == FAR_FUTURE_EPOCH and balance >= MAX_DEPOSIT_AMOUNT:
if validator.activation_eligibility_epoch == FAR_FUTURE_EPOCH and balance >= MAX_EFFECTIVE_BALANCE:
validator.activation_eligibility_epoch = get_current_epoch(state)
if is_active_validator(validator, get_current_epoch(state)) and balance < EJECTION_BALANCE:
@ -2335,10 +2335,11 @@ def process_transfer(state: BeaconState, transfer: Transfer) -> None:
assert get_balance(state, transfer.sender) >= max(transfer.amount, transfer.fee)
# A transfer is valid in only one slot
assert state.slot == transfer.slot
# Only withdrawn or not-yet-deposited accounts can transfer
# Only withdrawn, not-yet-deposited accounts, or the balance over MAX_EFFECTIVE_BALANCE can be transfered
assert (
get_current_epoch(state) >= state.validator_registry[transfer.sender].withdrawable_epoch or
state.validator_registry[transfer.sender].activation_epoch == FAR_FUTURE_EPOCH
state.validator_registry[transfer.sender].activation_epoch == FAR_FUTURE_EPOCH or
transfer.amount + transfer.fee >= get_balance(statetransfer.sender) - get_effective_balance(transfer.sender)
)
# Verify that the pubkey is valid
assert (