mirror of
https://github.com/logos-storage/nim-poseidon2.git
synced 2026-01-02 13:43:08 +00:00
minor improvements
This commit is contained in:
parent
acbc92dac7
commit
824daadd7e
@ -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
|
||||
|
||||
@ -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 )
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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":
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user