From 2f9b8b2f08767eed7ab75db8f0649b46bb9e81f8 Mon Sep 17 00:00:00 2001 From: vbuterin Date: Sun, 30 Sep 2018 14:38:51 -0400 Subject: [PATCH] Update casper_sharding_v2.1.md --- specs/casper_sharding_v2.1.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/specs/casper_sharding_v2.1.md b/specs/casper_sharding_v2.1.md index eb6ce5ec3..80445d6dc 100644 --- a/specs/casper_sharding_v2.1.md +++ b/specs/casper_sharding_v2.1.md @@ -298,15 +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 abstractly define `integer_sqrt` for use in reward/penalty calculations: +Finally, we abstractly define `integer_sqrt(x)` for use in reward/penalty calculations as the largest integer `n` such that `n**2 <= x`. Here is one possible implementation, though clients are free to use their own including standard libraries if available. + ```python def integer_sqrt(n): - return max(n in Z: n**2 <= x) + x = n + y = (x + 1) // 2 + while y < x: + x = y + y = (x + n // x) // 2 + return x ``` -We leave `integer_sqrt` implementation details to each particular language/framework. - - ### 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`