Merge branch 'integer-sqrt' of github.com:ethereum/eth2.0-specs into integer-sqrt

This commit is contained in:
Danny Ryan 2018-09-30 18:10:10 -05:00
commit 2ef9bc9f06
1 changed files with 3 additions and 4 deletions

View File

@ -298,19 +298,18 @@ def get_block_hash(active_state, curblock, slot):
`get_block_hash(*, *, h)` should always return the block in the chain at slot `h`, and `get_shards_and_committees_for_slot(*, h)` should not change unless the dynasty changes.
Finally, we define `int_sqrt` that for an input `n` returns `max(n in Z: n**2 <= x)`:
Finally, we abstractly define `int_sqrt(n)` for use in reward/penalty calculations as the largest integer `k` such that `k**2 <= n`. Here is one possible implementation, though clients are free to use their own including standard libraries if available and meet the specification.
```python
def int_sqrt(n):
k = n
while True:
newk = (k + (n // k)) // 2
if newk in (k, k+1): return k
if newk in (k, k+1):
return k
k = newk
```
### On startup
* Let `x = get_new_shuffling(bytes([0] * 32), validators, 1, 0)` and set `crystallized_state.shard_and_committee_for_slots` to `x + x`