From 9c7690ff0cb35b720ed8cee7838fecbe4a0b4aa8 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Mon, 13 Nov 2023 14:01:21 +0100 Subject: [PATCH] Use different compress functions for bottom layer and odd nodes --- poseidon2/merkle.nim | 16 ++++++++++++---- tests/poseidon2/testMerkle.nim | 24 +++++++++++++++++++----- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/poseidon2/merkle.nim b/poseidon2/merkle.nim index fe18210..0c4465f 100644 --- a/poseidon2/merkle.nim +++ b/poseidon2/merkle.nim @@ -1,10 +1,16 @@ import std/sequtils import constantine/math/arithmetic +import constantine/math/io/io_fields import ./types import ./io import ./compress -func merkleRoot*(xs: openArray[F]) : F = +const KeyNone = F.fromHex("0x0") +const KeyBottomLayer = F.fromHex("0x1") +const KeyOdd = F.fromHex("0x2") +const KeyOddAndBottomLayer = F.fromhex("0x3") + +func merkleRoot*(xs: openArray[F], isBottomLayer: static bool = true) : F = let a = low(xs) let b = high(xs) let m = b-a+1 @@ -24,11 +30,13 @@ func merkleRoot*(xs: openArray[F]) : F = ys = newSeq[F](halfn+1) for i in 0..