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 zero : F = getZero()
let external_round_const : array[24, F] = arrayFromHex( external_round_const_str ) let externalRoundConst : array[24, F] = arrayFromHex( externalRoundConstStr )
let internal_round_const : array[56, F] = arrayFromHex( internal_round_const_str ) let internalRoundConst : array[56, F] = arrayFromHex( internalRoundConstStr )
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
@ -25,14 +25,14 @@ proc sbox(x: var F) : void =
square(y) square(y)
x *= 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 var s = x ; s += y ; s += z
x += s x += s
y += s y += s
z += s z += s
proc internal_round(j: int; x, y, z: var F) = proc internalRound(j: int; x, y, z: var F) =
x += internal_round_const[j] x += internalRoundConst[j]
sbox(x) sbox(x)
var s = x ; s += y ; s += z var s = x ; s += y ; s += z
double(z) double(z)
@ -40,28 +40,28 @@ proc internal_round(j: int; x, y, z: var F) =
y += s y += s
z += s z += s
proc external_round(j: int; x, y, z : var F) = proc externalRound(j: int; x, y, z : var F) =
x += external_round_const[3*j+0] x += externalRoundConst[3*j+0]
y += external_round_const[3*j+1] y += externalRoundConst[3*j+1]
z += external_round_const[3*j+2] z += externalRoundConst[3*j+2]
sbox(x) ; sbox(y) ; sbox(z) sbox(x) ; sbox(y) ; sbox(z)
var s = x ; s += y ; s += z var s = x ; s += y ; s += z
x += s x += s
y += s y += s
z += s z += s
proc perm_inplace*(x, y, z : var F) = proc permInplace*(x, y, z : var F) =
linear_layer(x, y, z); linearLayer(x, y, z);
for j in 0..3: for j in 0..3:
external_round(j, x, y, z) externalRound(j, x, y, z)
for j in 0..55: for j in 0..55:
internal_round(j, x, y, z) internalRound(j, x, y, z)
for j in 4..7: for j in 4..7:
external_round(j, x, y, z) externalRound(j, x, y, z)
proc perm*(xyz: S) : S = proc perm*(xyz: S) : S =
var (x,y,z) = xyz var (x,y,z) = xyz
perm_inplace(x, y, z) permInplace(x, y, z)
return (x,y,z) return (x,y,z)
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
@ -70,10 +70,10 @@ proc compress*(a, b : F) : F =
var x = a var x = a
var y = b var y = b
var z : F ; setZero(z) var z : F ; setZero(z)
perm_inplace(x, y, z) permInplace(x, y, z)
return x return x
proc merkle_root*(xs: openArray[F]) : F = proc merkleRoot*(xs: openArray[F]) : F =
let a = low(xs) let a = low(xs)
let b = high(xs) let b = high(xs)
let m = b-a+1 let m = b-a+1
@ -84,11 +84,11 @@ proc merkle_root*(xs: openArray[F]) : F =
else: else:
let halfn : int = m div 2 let halfn : int = m div 2
let n : int = 2*halfn let n : int = 2*halfn
let is_odd : bool = (n != m) let isOdd : bool = (n != m)
var ys : seq[F] = newSeq[F](halfn) var ys : seq[F] = newSeq[F](halfn)
if not is_odd: if not isOdd:
for i in 0..<halfn: for i in 0..<halfn:
ys[i] = compress( xs[a+2*i], xs[a+2*i+1] ) 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: # and the last one:
ys[halfn-1] = compress( xs[a+n-2], zero ) 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" , [ "0x2c4c51fd1bb9567c27e99f5712b49e0574178b41b6f0a476cddc41d242cf2b43" ,
"0x1c5f8d18acb9c61ec6fcbfcda5356f1b3fdee7dc22c99a5b73a2750e5b054104" , "0x1c5f8d18acb9c61ec6fcbfcda5356f1b3fdee7dc22c99a5b73a2750e5b054104" ,
"0x2d3c1988b4541e4c045595b8d574e98a7c2820314a82e67a4e380f1c4541ba90" , "0x2d3c1988b4541e4c045595b8d574e98a7c2820314a82e67a4e380f1c4541ba90" ,
@ -30,7 +30,7 @@ let external_round_const_str* : array[24, string] =
"0x07a0693ff41476abb4664f3442596aa8399fdccf245d65882fce9a37c268aa04" , "0x07a0693ff41476abb4664f3442596aa8399fdccf245d65882fce9a37c268aa04" ,
"0x11eb49b07d33de2bd60ea68e7f652beda15644ed7855ee5a45763b576d216e8e" , "0x11eb49b07d33de2bd60ea68e7f652beda15644ed7855ee5a45763b576d216e8e" ,
"0x08f8887da6ce51a8c06041f64e22697895f34bacb8c0a39ec12bf597f7c67cfc" , "0x08f8887da6ce51a8c06041f64e22697895f34bacb8c0a39ec12bf597f7c67cfc" ,
# #
"0x2a912ec610191eb7662f86a52cc64c0122bd5ba762e1db8da79b5949fdd38092" , "0x2a912ec610191eb7662f86a52cc64c0122bd5ba762e1db8da79b5949fdd38092" ,
"0x2031d7fd91b80857aa1fef64e23cfad9a9ba8fe8c8d09de92b1edb592a44c290" , "0x2031d7fd91b80857aa1fef64e23cfad9a9ba8fe8c8d09de92b1edb592a44c290" ,
"0x0f81ebce43c47711751fa64d6c007221016d485641c28c507d04fd3dc7fba1d2" , "0x0f81ebce43c47711751fa64d6c007221016d485641c28c507d04fd3dc7fba1d2" ,
@ -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" , [ "0x15ce7e5ae220e8623a40b3a3b22d441eff0c9be1ae1d32f1b777af84eea7e38c" ,
"0x1bf60ac8bfff0f631983c93e218ca0d4a4059c254b4299b1d9984a07edccfaf0" , "0x1bf60ac8bfff0f631983c93e218ca0d4a4059c254b4299b1d9984a07edccfaf0" ,
"0x0fab0c9387cb2bec9dc11b2951088b9e1e1d2978542fc131f74a8f8fdac95b40" , "0x0fab0c9387cb2bec9dc11b2951088b9e1e1d2978542fc131f74a8f8fdac95b40" ,
@ -94,7 +94,7 @@ let internal_round_const_str* : array[56, string] =
"0x1b8c1252a5888f8cb2672effb5df49c633d3fd7183271488a1c40d0f88e7636e" , "0x1b8c1252a5888f8cb2672effb5df49c633d3fd7183271488a1c40d0f88e7636e" ,
"0x0f45697130f5498e2940568ef0d5e9e16b1095a6cdbb6411df20a973c605e70b" , "0x0f45697130f5498e2940568ef0d5e9e16b1095a6cdbb6411df20a973c605e70b" ,
"0x0780ccc403cdd68983acbd34cda41cacfb2cf911a93076bc25587b4b0aed4929" , "0x0780ccc403cdd68983acbd34cda41cacfb2cf911a93076bc25587b4b0aed4929" ,
"0x238d26ca97c691591e929f32199a643550f325f23a85d420080b289d7cecc9d4" "0x238d26ca97c691591e929f32199a643550f325f23a85d420080b289d7cecc9d4"
] ]
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------

View File

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

View File

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