minor improvements

This commit is contained in:
Balazs Komuves 2023-11-07 14:21:37 +01:00 committed by markspanbroek
parent 929793b9ad
commit 01aa256970
4 changed files with 10 additions and 15 deletions

View File

@ -36,8 +36,8 @@ func spongeWithRate1*(xs: openArray[F]) : F =
var s1 : F = zero
var s2 : F = zero
for i in 0..<n:
s0 += xs[a+i]
for x in xs:
s0 += x
permInplace(s0,s1,s2)
# padding

View File

@ -7,9 +7,6 @@ import ./roundconst
#-------------------------------------------------------------------------------
const zero* : F = getZero()
const one* : F = getOne()
const externalRoundConst : array[24, F] = arrayFromHex( externalRoundConstStr )
const internalRoundConst : array[56, F] = arrayFromHex( internalRoundConstStr )

View File

@ -18,19 +18,19 @@ func getZero*() : F =
setZero(z)
return z
func getOne*() : F =
var y : F
# y.fromUint(1'u32) # WTF, why does this not compile ???
y.fromHex("0x01")
return y
# for some reason this one does not compile... ???
# (when actually called)
# Remark: since `fromInt()` does not work at compile time, this doesn't either
func toF*(a: int) : F =
var y : F
y.fromInt(a)
return y
#-------------------------------------------------------------------------------
const zero* : F = getZero()
const one* : F = fromHex(F,"0x01") # note: `fromUint()` does not work at compile time
#-------------------------------------------------------------------------------
func hexToF*(s : string, endian: static Endianness = bigEndian) : F =
let bigint = B.fromHex(s, endian)
return F.fromBig(bigint)

View File

@ -59,7 +59,6 @@ suite "poseidon2":
for i in 1..n:
xs.add( toF(i) )
let h = spongeWithRate1(xs)
# echo(toDecimal(h))
check toDecimal(h) == expectedSpongeResultsRate1[n]
test "sponge with rate=2":
@ -68,7 +67,6 @@ suite "poseidon2":
for i in 1..n:
xs.add( toF(i) )
let h = spongeWithRate2(xs)
# echo(toDecimal(h))
check toDecimal(h) == expectedSpongeResultsRate2[n]
test "merkle root of field elements":