## Nim-Codex ## Copyright (c) 2023 Status Research & Development GmbH ## Licensed under either of ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * MIT license ([LICENSE-MIT](LICENSE-MIT)) ## at your option. ## This file may not be copied, modified, or distributed except according to ## those terms. {.push raises: [].} import std/sequtils import pkg/poseidon2 import pkg/constantine/math/io/io_fields import pkg/constantine/platforms/abstractions import pkg/questionable/results import ../utils import ../rng import ./merkletree export merkletree, poseidon2 const KeyNoneF = F.fromhex("0x0") KeyBottomLayerF = F.fromhex("0x1") KeyOddF = F.fromhex("0x2") KeyOddAndBottomLayerF = F.fromhex("0x3") Poseidon2Zero* = zero type Bn254Fr* = F Poseidon2Hash* = Bn254Fr PoseidonKeysEnum* = enum # can't use non-ordinals as enum values KeyNone KeyBottomLayer KeyOdd KeyOddAndBottomLayer Poseidon2Tree* = MerkleTree[Poseidon2Hash, PoseidonKeysEnum] Poseidon2Proof* = MerkleProof[Poseidon2Hash, PoseidonKeysEnum] proc `$`*(self: Poseidon2Tree): string = let root = if self.root.isOk: self.root.get.toHex else: "none" "Poseidon2Tree(" & " root: " & root & ", leavesCount: " & $self.leavesCount & ", levels: " & $self.levels & " )" proc `$`*(self: Poseidon2Proof): string = "Poseidon2Proof(" & " nleaves: " & $self.nleaves & ", index: " & $self.index & ", path: " & $self.path.mapIt( it.toHex ) & " )" func toArray32*(bytes: openArray[byte]): array[32, byte] = result[0..