mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 23:18:15 -05:00
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:
@@ -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--
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user