Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enables transfers of balance proportions > 32 ETH #936

Merged
merged 14 commits into from
Apr 23, 2019
10 changes: 5 additions & 5 deletions py_tests/phase0/block_processing/test_process_deposit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion py_tests/phase0/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
6 changes: 3 additions & 3 deletions py_tests/phase0/test_sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down
19 changes: 10 additions & 9 deletions specs/core/0_beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Expand Down Expand Up @@ -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
```
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
CarlBeek marked this conversation as resolved.
Show resolved Hide resolved
)
# Verify that the pubkey is valid
assert (
Expand Down