Convert under_scores to camelCase

This commit is contained in:
Mark Spanbroek 2023-10-24 14:16:54 +02:00 committed by markspanbroek
parent f73bce6aa1
commit 0e91bea0f6
4 changed files with 28 additions and 28 deletions

View File

@ -13,8 +13,8 @@ import poseidon2/roundconst
let zero : F = getZero()
let external_round_const : array[24, F] = arrayFromHex( external_round_const_str )
let internal_round_const : array[56, F] = arrayFromHex( internal_round_const_str )
let externalRoundConst : array[24, F] = arrayFromHex( externalRoundConstStr )
let internalRoundConst : array[56, F] = arrayFromHex( internalRoundConstStr )
#-------------------------------------------------------------------------------
@ -25,14 +25,14 @@ proc sbox(x: var F) : void =
square(y)
x *= y
proc linear_layer(x, y, z : var F) =
proc linearLayer(x, y, z : var F) =
var s = x ; s += y ; s += z
x += s
y += s
z += s
proc internal_round(j: int; x, y, z: var F) =
x += internal_round_const[j]
proc internalRound(j: int; x, y, z: var F) =
x += internalRoundConst[j]
sbox(x)
var s = x ; s += y ; s += z
double(z)
@ -40,28 +40,28 @@ proc internal_round(j: int; x, y, z: var F) =
y += s
z += s
proc external_round(j: int; x, y, z : var F) =
x += external_round_const[3*j+0]
y += external_round_const[3*j+1]
z += external_round_const[3*j+2]
proc externalRound(j: int; x, y, z : var F) =
x += externalRoundConst[3*j+0]
y += externalRoundConst[3*j+1]
z += externalRoundConst[3*j+2]
sbox(x) ; sbox(y) ; sbox(z)
var s = x ; s += y ; s += z
x += s
y += s
z += s
proc perm_inplace*(x, y, z : var F) =
linear_layer(x, y, z);
proc permInplace*(x, y, z : var F) =
linearLayer(x, y, z);
for j in 0..3:
external_round(j, x, y, z)
externalRound(j, x, y, z)
for j in 0..55:
internal_round(j, x, y, z)
internalRound(j, x, y, z)
for j in 4..7:
external_round(j, x, y, z)
externalRound(j, x, y, z)
proc perm*(xyz: S) : S =
var (x,y,z) = xyz
perm_inplace(x, y, z)
permInplace(x, y, z)
return (x,y,z)
#-------------------------------------------------------------------------------
@ -70,10 +70,10 @@ proc compress*(a, b : F) : F =
var x = a
var y = b
var z : F ; setZero(z)
perm_inplace(x, y, z)
permInplace(x, y, z)
return x
proc merkle_root*(xs: openArray[F]) : F =
proc merkleRoot*(xs: openArray[F]) : F =
let a = low(xs)
let b = high(xs)
let m = b-a+1
@ -84,11 +84,11 @@ proc merkle_root*(xs: openArray[F]) : F =
else:
let halfn : int = m div 2
let n : int = 2*halfn
let is_odd : bool = (n != m)
let isOdd : bool = (n != m)
var ys : seq[F] = newSeq[F](halfn)
if not is_odd:
if not isOdd:
for i in 0..<halfn:
ys[i] = compress( xs[a+2*i], xs[a+2*i+1] )
@ -98,7 +98,7 @@ proc merkle_root*(xs: openArray[F]) : F =
# and the last one:
ys[halfn-1] = compress( xs[a+n-2], zero )
return merkle_root(ys)
return merkleRoot(ys)
#-------------------------------------------------------------------------------

View File

@ -2,7 +2,7 @@
#-------------------------------------------------------------------------------
let external_round_const_str* : array[24, string] =
let externalRoundConstStr* : array[24, string] =
[ "0x2c4c51fd1bb9567c27e99f5712b49e0574178b41b6f0a476cddc41d242cf2b43" ,
"0x1c5f8d18acb9c61ec6fcbfcda5356f1b3fdee7dc22c99a5b73a2750e5b054104" ,
"0x2d3c1988b4541e4c045595b8d574e98a7c2820314a82e67a4e380f1c4541ba90" ,
@ -38,7 +38,7 @@ let external_round_const_str* : array[24, string] =
#-------------------------------------------------------------------------------
let internal_round_const_str* : array[56, string] =
let internalRoundConstStr* : array[56, string] =
[ "0x15ce7e5ae220e8623a40b3a3b22d441eff0c9be1ae1d32f1b777af84eea7e38c" ,
"0x1bf60ac8bfff0f631983c93e218ca0d4a4059c254b4299b1d9984a07edccfaf0" ,
"0x0fab0c9387cb2bec9dc11b2951088b9e1e1d2978542fc131f74a8f8fdac95b40" ,

View File

@ -7,7 +7,7 @@ import
#-------------------------------------------------------------------------------
type B* = BigInt[254]
type F* = Fr[BN254_Snarks]
type F* = Fr[BN254Snarks]
type S* = (F,F,F)
#-------------------------------------------------------------------------------

View File

@ -14,7 +14,7 @@ suite "poseidon2":
var y: F = toF(1)
var z: F = toF(2)
perm_inplace(x, y, z)
permInplace(x, y, z)
check toDecimal(x) == "21882471761025344482456282050943515707267606647948403374880378562101343146243"
check toDecimal(y) == "09030699330013392132529464674294378792132780497765201297316864012141442630280"
@ -27,6 +27,6 @@ suite "poseidon2":
for i in 1..n:
xs.add( toF(i) )
let root = merkle_root(xs)
let root = merkleRoot(xs)
check toHex(root) == "0x1eabbb64b76d5aecd393601c4a01878450e23f45fe8b2748bb63a615351b11d1"