From fa7c27a833126072e7fe116df0b26826b80206b0 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Tue, 31 Oct 2023 13:40:07 +0100 Subject: [PATCH] move unmarshal into its own module called 'io' Includes separate tests for unmarshalling that were previously tested as part of the merkleRoot calculation. Includes tests for unmarshalling little endian and big endian byte arrays. --- poseidon2.nim | 20 +-------- poseidon2/io.nim | 18 ++++++++ tests/poseidon2/testIo.nim | 36 ++++++++++++++++ tests/poseidon2/testPoseidon2.nim | 39 +++++++++++++++++ tests/test.nim | 72 ++----------------------------- 5 files changed, 97 insertions(+), 88 deletions(-) create mode 100644 poseidon2/io.nim create mode 100644 tests/poseidon2/testIo.nim create mode 100644 tests/poseidon2/testPoseidon2.nim diff --git a/poseidon2.nim b/poseidon2.nim index f750564..34a84cd 100644 --- a/poseidon2.nim +++ b/poseidon2.nim @@ -1,13 +1,10 @@ - -# import std/sugar - import constantine/math/arithmetic, - constantine/math/io/io_bigints, constantine/math/config/curves import poseidon2/types import poseidon2/roundconst +import poseidon2/io #------------------------------------------------------------------------------- @@ -100,20 +97,5 @@ proc merkleRoot*(xs: openArray[F]) : F = return merkleRoot(ys) -proc unmarshal( - _: type F, - bytes: openArray[byte], - endian: static Endianness): seq[F] = - const chunkLen = 31 - var elements: seq[F] - var i = 0 - while i < bytes.len: - let chunk = bytes[i..