mirror of
https://github.com/logos-storage/nim-poseidon2.git
synced 2026-01-04 06:33:11 +00:00
minor improvements
This commit is contained in:
parent
929793b9ad
commit
01aa256970
@ -36,8 +36,8 @@ func spongeWithRate1*(xs: openArray[F]) : F =
|
|||||||
var s1 : F = zero
|
var s1 : F = zero
|
||||||
var s2 : F = zero
|
var s2 : F = zero
|
||||||
|
|
||||||
for i in 0..<n:
|
for x in xs:
|
||||||
s0 += xs[a+i]
|
s0 += x
|
||||||
permInplace(s0,s1,s2)
|
permInplace(s0,s1,s2)
|
||||||
|
|
||||||
# padding
|
# padding
|
||||||
|
|||||||
@ -7,9 +7,6 @@ import ./roundconst
|
|||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
|
|
||||||
const zero* : F = getZero()
|
|
||||||
const one* : F = getOne()
|
|
||||||
|
|
||||||
const externalRoundConst : array[24, F] = arrayFromHex( externalRoundConstStr )
|
const externalRoundConst : array[24, F] = arrayFromHex( externalRoundConstStr )
|
||||||
const internalRoundConst : array[56, F] = arrayFromHex( internalRoundConstStr )
|
const internalRoundConst : array[56, F] = arrayFromHex( internalRoundConstStr )
|
||||||
|
|
||||||
|
|||||||
@ -18,19 +18,19 @@ func getZero*() : F =
|
|||||||
setZero(z)
|
setZero(z)
|
||||||
return z
|
return z
|
||||||
|
|
||||||
func getOne*() : F =
|
# Remark: since `fromInt()` does not work at compile time, this doesn't either
|
||||||
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)
|
|
||||||
func toF*(a: int) : F =
|
func toF*(a: int) : F =
|
||||||
var y : F
|
var y : F
|
||||||
y.fromInt(a)
|
y.fromInt(a)
|
||||||
return y
|
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 =
|
func hexToF*(s : string, endian: static Endianness = bigEndian) : F =
|
||||||
let bigint = B.fromHex(s, endian)
|
let bigint = B.fromHex(s, endian)
|
||||||
return F.fromBig(bigint)
|
return F.fromBig(bigint)
|
||||||
|
|||||||
@ -59,7 +59,6 @@ suite "poseidon2":
|
|||||||
for i in 1..n:
|
for i in 1..n:
|
||||||
xs.add( toF(i) )
|
xs.add( toF(i) )
|
||||||
let h = spongeWithRate1(xs)
|
let h = spongeWithRate1(xs)
|
||||||
# echo(toDecimal(h))
|
|
||||||
check toDecimal(h) == expectedSpongeResultsRate1[n]
|
check toDecimal(h) == expectedSpongeResultsRate1[n]
|
||||||
|
|
||||||
test "sponge with rate=2":
|
test "sponge with rate=2":
|
||||||
@ -68,7 +67,6 @@ suite "poseidon2":
|
|||||||
for i in 1..n:
|
for i in 1..n:
|
||||||
xs.add( toF(i) )
|
xs.add( toF(i) )
|
||||||
let h = spongeWithRate2(xs)
|
let h = spongeWithRate2(xs)
|
||||||
# echo(toDecimal(h))
|
|
||||||
check toDecimal(h) == expectedSpongeResultsRate2[n]
|
check toDecimal(h) == expectedSpongeResultsRate2[n]
|
||||||
|
|
||||||
test "merkle root of field elements":
|
test "merkle root of field elements":
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user