diff --git a/poseidon2/merkle.nim b/poseidon2/merkle.nim index ad5e3b4..b24c83f 100644 --- a/poseidon2/merkle.nim +++ b/poseidon2/merkle.nim @@ -15,28 +15,28 @@ func merkleRoot(xs: openArray[F], isBottomLayer: static bool) : F = let b = high(xs) let m = b-a+1 - if m==1 and not isBottomLayer: - return xs[a] + when not isBottomLayer: + if m==1: + return xs[a] + let halfn : int = m div 2 + let n : int = 2*halfn + let isOdd : bool = (n != m) + + var ys : seq[F] + if not isOdd: + ys = newSeq[F](halfn) else: - let halfn : int = m div 2 - let n : int = 2*halfn - let isOdd : bool = (n != m) + ys = newSeq[F](halfn+1) - var ys : seq[F] - if not isOdd: - ys = newSeq[F](halfn) - else: - ys = newSeq[F](halfn+1) + for i in 0..