Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

https://github.com/ethereum/consensus-specs/pull/3600 #5896

Merged
merged 1 commit into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion beacon_chain/spec/helpers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ func shortLog*(v: FinalityCheckpoints): auto =

chronicles.formatIt FinalityCheckpoints: it.shortLog

# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.6/specs/phase0/beacon-chain.md#integer_squareroot
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.7/specs/phase0/beacon-chain.md#integer_squareroot
func integer_squareroot*(n: SomeInteger): SomeInteger =
## Return the largest integer ``x`` such that ``x**2 <= n``.
doAssert n >= 0'u64

if n == high(uint64):
return 4294967295'u64

var
x = n
y = (x + 1) div 2
Expand Down
7 changes: 6 additions & 1 deletion tests/test_helpers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ import
suite "Spec helpers":
test "integer_squareroot":
check:
integer_squareroot(0'u64) == 0'u64
integer_squareroot(1'u64) == 1'u64
integer_squareroot(2'u64) == 1'u64
integer_squareroot(3'u64) == 1'u64
integer_squareroot(4'u64) == 2'u64
integer_squareroot(5'u64) == 2'u64

# https://github.com/ethereum/consensus-specs/pull/3600
integer_squareroot(0'u64) == 0'u64
integer_squareroot(100'u64) == 10'u64
integer_squareroot(18446744073709551614'u64) == 4294967295'u64
integer_squareroot(18446744073709551615'u64) == 4294967295'u64

test "build_proof - BeaconState":
var
forked = newClone(initGenesisState())
Expand Down
Loading