Fix logarithm of 2 (#10275)

* Fix logarithm of 2

* add regression test

* Update encoding/ssz/merkleize.go

Co-authored-by: Nishant Das <nishdas93@gmail.com>

Co-authored-by: Nishant Das <nishdas93@gmail.com>
This commit is contained in:
Potuz
2022-02-23 09:44:04 -03:00
committed by GitHub
parent 3bb2acfc7d
commit be722604f7
2 changed files with 6 additions and 2 deletions

View File

@@ -34,8 +34,8 @@ func Depth(v uint64) (out uint8) {
// Then adding 1 to it to not get the index of the first bit, but the length of the bits (depth of tree)
// Zero is a special case, it has a 0 depth.
// Example:
// (in out): (0 0), (1 1), (2 1), (3 2), (4 2), (5 3), (6 3), (7 3), (8 3), (9 4)
if v == 0 {
// (in out): (0 0), (1 0), (2 1), (3 2), (4 2), (5 3), (6 3), (7 3), (8 3), (9 4)
if v <= 1 {
return 0
}
v--

View File

@@ -112,3 +112,7 @@ func TestConstructProofNormalPath(t *testing.T) {
assert.DeepEqual(t, result[i], v)
}
}
func TestDepthOfOne(t *testing.T) {
assert.Equal(t, uint8(0), ssz.Depth(1))
}