mirror of
https://github.com/codex-storage/nim-poseidon2.git
synced 2025-02-23 00:08:05 +00:00
Ensure that merkle root of single element is compressed
This commit is contained in:
parent
9c7690ff0c
commit
4bd56bb839
@ -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:
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user