Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 34 additions & 30 deletions zokrates_stdlib/stdlib/hashes/pedersen/512bit.zok
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import "utils/multiplexer/lookup3bitSigned" as sel3s
import "utils/multiplexer/lookup2bit" as sel2
import "ecc/babyjubjubParams" as context
Expand All @@ -15,35 +16,38 @@ import "EMBED/u32_from_bits" as from_bits
// #%%
// entropy = np.random.bytes(64)
// hasher = PedersenHasher("test")
// hasher.hash_bytes(entropy)
// print(hasher.dsl_code)

// 512bit to 256bit Pedersen hash using compression of the field elements
def main(u32[16] input) -> u32[8]:

bool[512] e = [ \
...to_bits(input[0]),
...to_bits(input[1]),
...to_bits(input[2]),
...to_bits(input[3]),
...to_bits(input[4]),
...to_bits(input[5]),
...to_bits(input[6]),
...to_bits(input[7]),
...to_bits(input[8]),
...to_bits(input[9]),
...to_bits(input[10]),
...to_bits(input[11]),
...to_bits(input[12]),
...to_bits(input[13]),
...to_bits(input[14]),
...to_bits(input[15])
def main(u32[16] inputs) -> u32[8]:
bool[513] e = [\
...to_bits(inputs[0]),
...to_bits(inputs[1]),
...to_bits(inputs[2]),
...to_bits(inputs[3]),
...to_bits(inputs[4]),
...to_bits(inputs[5]),
...to_bits(inputs[6]),
...to_bits(inputs[7]),
...to_bits(inputs[8]),
...to_bits(inputs[9]),
...to_bits(inputs[10]),
...to_bits(inputs[11]),
...to_bits(inputs[12]),
...to_bits(inputs[13]),
...to_bits(inputs[14]),
...to_bits(inputs[15]),
false
]

BabyJubJubParams context = context()
field[2] a = context.INFINITY //Infinity
field cx = 0
field cy = 0

//Round 0
field cx = sel3s([e[0], e[1], e[2]], [13418723823902222986275588345615650707197303761863176429873001977640541977977 , 8366451672790208592553809639953117385619257483837439526516290319251622927412, 1785026334726838136757054176272745265857971873904476677125553010508875025629, 15763987975760561753692294837740043971877392788040801334205375164715487005236])
field cy = sel2([e[0], e[1]], [15255921313433251341520743036334816584226787412845488772781699434149539664639 , 10916775373885716961512013142444429405184550001421868906213743991404593770484, 18533662942827602783563125901366807026309605479742251601915445402562880550265, 12754584346112149619040942896930712185968371085994381911052593922432846916845])
cx = sel3s([e[0], e[1], e[2]], [13418723823902222986275588345615650707197303761863176429873001977640541977977 , 8366451672790208592553809639953117385619257483837439526516290319251622927412, 1785026334726838136757054176272745265857971873904476677125553010508875025629, 15763987975760561753692294837740043971877392788040801334205375164715487005236])
cy = sel2([e[0], e[1]], [15255921313433251341520743036334816584226787412845488772781699434149539664639 , 10916775373885716961512013142444429405184550001421868906213743991404593770484, 18533662942827602783563125901366807026309605479742251601915445402562880550265, 12754584346112149619040942896930712185968371085994381911052593922432846916845])
a = add(a, [cx, cy], context)
//Round 1
cx = sel3s([e[3], e[4], e[5]], [10096735692467598736728394557736034054031417419721869067082824451240861468728 , 6979151010236415881632946866847657030447196774231162748523315765559549846746, 12137947022495312670974525048647679757468392619153927921382150023166867027471, 10624360821702266736197468438435445939719745367234393212061381062942588576905])
Expand Down Expand Up @@ -722,19 +726,19 @@ def main(u32[16] input) -> u32[8]:
cy = sel2([e[507], e[508]], [18191174947339798787646910619446409943766046946921136035021645191602921923040 , 16559060177998758852323304784771936179434931576336411584121379336820727372618, 13858115732979799183025726471151602712224733686530960054365665740611187232029, 9933192519609817862698304326029579651414877338671776883175639003837130283966])
a = add(a, [cx, cy], context)
//Round 170
cx = sel3s([e[510], e[511], false], [3342564788366736273905106071612128667477972061160313630133110787799686301495 , 13766193863701503939885263345152684798552605679140222504700163745347162493183, 18523279471468319520962369406962457727155204375043681943707151819380964978377, 8094164074569624021939357073285075790695279643883973800173037824312344195506])
cx = sel3s([e[510], e[511], e[512]], [3342564788366736273905106071612128667477972061160313630133110787799686301495 , 13766193863701503939885263345152684798552605679140222504700163745347162493183, 18523279471468319520962369406962457727155204375043681943707151819380964978377, 8094164074569624021939357073285075790695279643883973800173037824312344195506])
cy = sel2([e[510], e[511]], [2329094643034533408459502544740928833981119919633412709248656884170940780093 , 3216329736050668550647765981020076413548845117352735257893224753954595290363, 18710403072495673647060422294369054840513840567808020912157404388689648711093, 9785201456176703812798077455183487364035650707229293534561747881523562553649])
a = add(a, [cx, cy], context)

bool[256] aC = edwardsCompress(a)

return [\
from_bits(aC[0..32]),
from_bits(aC[32..64]),
from_bits(aC[64..96]),
from_bits(aC[96..128]),
from_bits(aC[128..160]),
from_bits(aC[160..192]),
from_bits(aC[192..224]),
from_bits(aC[0..32]),
from_bits(aC[32..64]),
from_bits(aC[64..96]),
from_bits(aC[96..128]),
from_bits(aC[128..160]),
from_bits(aC[160..192]),
from_bits(aC[192..224]),
from_bits(aC[224..256])
]