Merge pull request #919 from ethereum/JustinDrake-patch-10

Cleaner dust checking in transfers
This commit is contained in:
Diederik Loerakker 2019-04-14 23:04:12 +10:00 committed by GitHub
commit 2a88dff2be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 8 deletions

View File

@ -2333,14 +2333,6 @@ def process_transfer(state: BeaconState, transfer: Transfer) -> None:
""" """
# Verify the amount and fee aren't individually too big (for anti-overflow purposes) # Verify the amount and fee aren't individually too big (for anti-overflow purposes)
assert get_balance(state, transfer.sender) >= max(transfer.amount, transfer.fee) assert get_balance(state, transfer.sender) >= max(transfer.amount, transfer.fee)
# Verify that we have enough ETH to send, and that after the transfer the balance will be either
# exactly zero or at least MIN_DEPOSIT_AMOUNT
assert (
get_balance(state, transfer.sender) == transfer.amount + transfer.fee or
get_balance(state, transfer.sender) >= transfer.amount + transfer.fee + MIN_DEPOSIT_AMOUNT
)
# No self-transfers (to enforce >= MIN_DEPOSIT_AMOUNT or zero balance invariant)
assert transfer.sender != transfer.recipient
# A transfer is valid in only one slot # A transfer is valid in only one slot
assert state.slot == transfer.slot assert state.slot == transfer.slot
# Only withdrawn or not-yet-deposited accounts can transfer # Only withdrawn or not-yet-deposited accounts can transfer
@ -2364,6 +2356,9 @@ def process_transfer(state: BeaconState, transfer: Transfer) -> None:
decrease_balance(state, transfer.sender, transfer.amount + transfer.fee) decrease_balance(state, transfer.sender, transfer.amount + transfer.fee)
increase_balance(state, transfer.recipient, transfer.amount) increase_balance(state, transfer.recipient, transfer.amount)
increase_balance(state, get_beacon_proposer_index(state, state.slot), transfer.fee) increase_balance(state, get_beacon_proposer_index(state, state.slot), transfer.fee)
# Verify balances are not dust
assert not (0 < get_balance(state, transfer.sender) < MIN_DEPOSIT_AMOUNT)
assert not (0 < get_balance(state, transfer.recipient) < MIN_DEPOSIT_AMOUNT)
``` ```
#### State root verification #### State root verification