Ensure that merkle root of single element is compressed

This commit is contained in:
Mark Spanbroek 2023-11-13 14:09:51 +01:00 committed by markspanbroek
parent 9c7690ff0c
commit 4bd56bb839
2 changed files with 9 additions and 1 deletions

View File

@ -15,7 +15,7 @@ func merkleRoot*(xs: openArray[F], isBottomLayer: static bool = true) : F =
let b = high(xs)
let m = b-a+1
if m==1:
if m==1 and not isBottomLayer:
return xs[a]
else:

View File

@ -48,6 +48,14 @@ suite "merkle root":
let b = a & @[0.toF]
check not bool(merkleRoot(a) == merkleRoot(b))
test "merkle root of single element does not equal the element":
check not bool(merkleRoot([1.toF]) == 1.toF)
test "merkle root differs from merkle root of merkle root":
let a = 1.toF
let b = 2.toF
check not bool(merkleRoot([a, b]) == merkleRoot([merkleRoot([a, b])]))
test "merkle root of bytes":
let bytes = toSeq 1'u8..80'u8
let root = merkleRoot(bytes)