Cleaner dust checking in transfers

Inspired by [this](https://github.com/ethereum/eth2.0-specs/pull/916#commitcomment-33170877).
This commit is contained in:
Justin 2019-04-14 21:53:32 +10:00 committed by GitHub
parent 7840d29f2d
commit a376b6607f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 8 deletions

View File

@ -2334,14 +2334,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
@ -2365,6 +2357,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