diff --git a/encoding/ssz/merkleize.go b/encoding/ssz/merkleize.go index 67caa55783..a9f542f1b7 100644 --- a/encoding/ssz/merkleize.go +++ b/encoding/ssz/merkleize.go @@ -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-- diff --git a/encoding/ssz/merkleize_test.go b/encoding/ssz/merkleize_test.go index 72fb0c6583..c0cf20e361 100644 --- a/encoding/ssz/merkleize_test.go +++ b/encoding/ssz/merkleize_test.go @@ -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)) +}