quick comment on avoiding underflow

This commit is contained in:
Danny Ryan 2019-06-29 15:49:11 -06:00
parent 23909ca727
commit ded936ebad
No known key found for this signature in database
GPG Key ID: 2765A792E42CE07A
1 changed files with 2 additions and 6 deletions

View File

@ -737,8 +737,7 @@ def get_randao_mix(state: BeaconState,
epoch: Epoch) -> Hash:
"""
Return the randao mix at a recent ``epoch``.
``epoch`` expected to be between (current_epoch - EPOCHS_PER_HISTORICAL_VECTOR, current_epoch], unless
otherwise noted at a call site.
``epoch`` expected to be between (current_epoch - EPOCHS_PER_HISTORICAL_VECTOR, current_epoch].
"""
return state.randao_mixes[epoch % EPOCHS_PER_HISTORICAL_VECTOR]
```
@ -763,12 +762,9 @@ def generate_seed(state: BeaconState,
epoch: Epoch) -> Hash:
"""
Generate a seed for the given ``epoch``.
Note that avoiding the underflow on ``get_randao_mix`` here violates
the epoch validity condition given in that function's comment.
"""
return hash(
get_randao_mix(state, Epoch(epoch + EPOCHS_PER_HISTORICAL_VECTOR - MIN_SEED_LOOKAHEAD)) +
get_randao_mix(state, Epoch(epoch + EPOCHS_PER_HISTORICAL_VECTOR - MIN_SEED_LOOKAHEAD)) + #avoid underflow
get_active_index_root(state, epoch) +
int_to_bytes(epoch, length=32)
)