add some convenience functions converting digests to field element sequences

This commit is contained in:
Balazs Komuves 2024-10-22 12:23:05 +02:00
parent 2d201ea8bb
commit bd5b805b80
No known key found for this signature in database
GPG Key ID: F63B7AEF18435562
2 changed files with 14 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import ./types
# build system hack
const
# REMARK: currentSourcePath = ~/.nimble/pkgs/goldilocks_hash-0.0.1/goldilocks_hash/goldilocks.nim
root = currentSourcePath.parentDir.parentDir
{. passc: "-I" & root & "/cbits" .}

View File

@ -1,4 +1,5 @@
import std/sequtils
import std/strformat
#-------------------------------------------------------------------------------
@ -55,6 +56,15 @@ proc `$`*(x: Digest): string = return $(fromDigest(x))
#-------------------------------------------------------------------------------
func digestToFeltSeq*( d: Digest ): seq[F] =
var output: seq[F] = newSeq[F]( 4 )
let f4 = fromDigest( d )
output[0] = f4[0]
output[1] = f4[1]
output[2] = f4[2]
output[3] = f4[3]
return output
func digestSeqToFeltSeq*( ds: seq[Digest] ): seq[F] =
let n = ds.len
var output: seq[F] = newSeq[F]( 4*n )
@ -67,6 +77,9 @@ func digestSeqToFeltSeq*( ds: seq[Digest] ): seq[F] =
output[j+3] = f4[3]
return output
func digestSeqToFeltSeqSeq*( ds: seq[Digest] ): seq[seq[F]]
= ds.map(digestToFeltSeq)
#-------------------------------------------------------------------------------
func numberOfBits*(T: type): int {.compileTime.} =