diff --git a/.gitmodules b/.gitmodules index b7cb5924..e47105ca 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,7 +1,3 @@ -[submodule "rln/vendor/rln"] - path = rln/vendor/rln - ignore = dirty - url = https://github.com/Rate-Limiting-Nullifier/rln_circuits.git [submodule "semaphore/vendor/semaphore"] path = semaphore/vendor/semaphore ignore = dirty diff --git a/rln/README.md b/rln/README.md index 3aab6ec5..fe6ae2b2 100644 --- a/rln/README.md +++ b/rln/README.md @@ -56,7 +56,7 @@ However, if `N` is too big, this might require a bigger Powers of Tau ceremony t In such case we refer to the official [Circom documentation](https://docs.circom.io/getting-started/proving-circuits/#powers-of-tau) for instructions on how to run an appropriate Powers of Tau ceremony and Phase 2 in order to compile the desired circuit. -Currently, the `rln` module comes with three [pre-compiled](https://github.com/vacp2p/zerokit/tree/master/rln/resources) RLN circuits having Merkle tree of height `15`, `19` and `20`, respectively. +Currently, the `rln` module comes with 2 [pre-compiled](https://github.com/vacp2p/zerokit/tree/master/rln/resources) RLN circuits having Merkle tree of height `20` and `32`, respectively. ## Getting started diff --git a/rln/resources/tree_height_15/rln.wasm b/rln/resources/tree_height_15/rln.wasm deleted file mode 100644 index dbbfb652..00000000 Binary files a/rln/resources/tree_height_15/rln.wasm and /dev/null differ diff --git a/rln/resources/tree_height_15/rln_final.zkey b/rln/resources/tree_height_15/rln_final.zkey deleted file mode 100644 index 89a7c381..00000000 Binary files a/rln/resources/tree_height_15/rln_final.zkey and /dev/null differ diff --git a/rln/resources/tree_height_15/verification_key.json b/rln/resources/tree_height_15/verification_key.json deleted file mode 100644 index e4bb03c8..00000000 --- a/rln/resources/tree_height_15/verification_key.json +++ /dev/null @@ -1,119 +0,0 @@ -{ - "protocol": "groth16", - "curve": "bn128", - "nPublic": 6, - "vk_alpha_1": [ - "20124996762962216725442980738609010303800849578410091356605067053491763969391", - "9118593021526896828671519912099489027245924097793322973632351264852174143923", - "1" - ], - "vk_beta_2": [ - [ - "4693952934005375501364248788849686435240706020501681709396105298107971354382", - "14346958885444710485362620645446987998958218205939139994511461437152241966681" - ], - [ - "16851772916911573982706166384196538392731905827088356034885868448550849804972", - "823612331030938060799959717749043047845343400798220427319188951998582076532" - ], - [ - "1", - "0" - ] - ], - "vk_gamma_2": [ - [ - "10857046999023057135944570762232829481370756359578518086990519993285655852781", - "11559732032986387107991004021392285783925812861821192530917403151452391805634" - ], - [ - "8495653923123431417604973247489272438418190587263600148770280649306958101930", - "4082367875863433681332203403145435568316851327593401208105741076214120093531" - ], - [ - "1", - "0" - ] - ], - "vk_delta_2": [ - [ - "1361919643088555407518565462732544232965454074504004321739078395285189557133", - "20823246840633598579879223919854294301857184404415306521912631074982696570306" - ], - [ - "7088590198103342249937795923142619828109070290720888704402714617857746884833", - "8191367139632195506244169264298620546181137131063303219908889318280111188437" - ], - [ - "1", - "0" - ] - ], - "vk_alphabeta_12": [ - [ - [ - "12608968655665301215455851857466367636344427685631271961542642719683786103711", - "9849575605876329747382930567422916152871921500826003490242628251047652318086" - ], - [ - "6322029441245076030714726551623552073612922718416871603535535085523083939021", - "8700115492541474338049149013125102281865518624059015445617546140629435818912" - ], - [ - "10674973475340072635573101639867487770811074181475255667220644196793546640210", - "2926286967251299230490668407790788696102889214647256022788211245826267484824" - ] - ], - [ - [ - "9660441540778523475944706619139394922744328902833875392144658911530830074820", - "19548113127774514328631808547691096362144426239827206966690021428110281506546" - ], - [ - "1870837942477655969123169532603615788122896469891695773961478956740992497097", - "12536105729661705698805725105036536744930776470051238187456307227425796690780" - ], - [ - "21811903352654147452884857281720047789720483752548991551595462057142824037334", - "19021616763967199151052893283384285352200445499680068407023236283004353578353" - ] - ] - ], - "IC": [ - [ - "17643142412395322664866141827318671249236739056291610144830020671604112279111", - "13273439661778801509295280274403992505521239023074387826870538372514206268318", - "1" - ], - [ - "12325966053136615826793633393742326952102053533176311103856731330114882211366", - "6439956820140153832120005353467272867287237423425778281905068783317736451260", - "1" - ], - [ - "20405310272367450124741832665322768131899487413829191383721623069139009993137", - "21336772016824870564600007750206596010566056069977718959140462128560786193566", - "1" - ], - [ - "4007669092231576644992949839487535590075070172447826102934640178940614212519", - "7597503385395289202372182678960254605827199004598882158153019657732525465207", - "1" - ], - [ - "4545695279389338758267531646940033299700127241196839077811942492841603458462", - "6635771967009274882904456432128877995932122611166121203658485990305433499873", - "1" - ], - [ - "7876954805169515500747828488548350352651069599547377092970620945851311591012", - "7571431725691513008054581132582771105743462534789373657638701712901679323321", - "1" - ], - [ - "5563973122249220346301217166900152021860462617567141574881706390202619333219", - "5147729144109676590873823097632042430451708874867871369293332620382492068692", - "1" - ] - ] -} \ No newline at end of file diff --git a/rln/resources/tree_height_19/rln.wasm b/rln/resources/tree_height_19/rln.wasm deleted file mode 100644 index 0d3da9a7..00000000 Binary files a/rln/resources/tree_height_19/rln.wasm and /dev/null differ diff --git a/rln/resources/tree_height_19/rln_final.zkey b/rln/resources/tree_height_19/rln_final.zkey deleted file mode 100644 index de38bad1..00000000 Binary files a/rln/resources/tree_height_19/rln_final.zkey and /dev/null differ diff --git a/rln/resources/tree_height_19/verification_key.json b/rln/resources/tree_height_19/verification_key.json deleted file mode 100644 index 48455a56..00000000 --- a/rln/resources/tree_height_19/verification_key.json +++ /dev/null @@ -1,119 +0,0 @@ -{ - "protocol": "groth16", - "curve": "bn128", - "nPublic": 6, - "vk_alpha_1": [ - "20124996762962216725442980738609010303800849578410091356605067053491763969391", - "9118593021526896828671519912099489027245924097793322973632351264852174143923", - "1" - ], - "vk_beta_2": [ - [ - "4693952934005375501364248788849686435240706020501681709396105298107971354382", - "14346958885444710485362620645446987998958218205939139994511461437152241966681" - ], - [ - "16851772916911573982706166384196538392731905827088356034885868448550849804972", - "823612331030938060799959717749043047845343400798220427319188951998582076532" - ], - [ - "1", - "0" - ] - ], - "vk_gamma_2": [ - [ - "10857046999023057135944570762232829481370756359578518086990519993285655852781", - "11559732032986387107991004021392285783925812861821192530917403151452391805634" - ], - [ - "8495653923123431417604973247489272438418190587263600148770280649306958101930", - "4082367875863433681332203403145435568316851327593401208105741076214120093531" - ], - [ - "1", - "0" - ] - ], - "vk_delta_2": [ - [ - "16125279975606773676640811113051624654121459921695914044301154938920321009721", - "14844345250267029614093295465313288254479124604567709177260777529651293576873" - ], - [ - "20349277326920398483890518242229158117668855310237215044647746783223259766294", - "19338776107510040969200058390413661029003750817172740054990168933780935479540" - ], - [ - "1", - "0" - ] - ], - "vk_alphabeta_12": [ - [ - [ - "12608968655665301215455851857466367636344427685631271961542642719683786103711", - "9849575605876329747382930567422916152871921500826003490242628251047652318086" - ], - [ - "6322029441245076030714726551623552073612922718416871603535535085523083939021", - "8700115492541474338049149013125102281865518624059015445617546140629435818912" - ], - [ - "10674973475340072635573101639867487770811074181475255667220644196793546640210", - "2926286967251299230490668407790788696102889214647256022788211245826267484824" - ] - ], - [ - [ - "9660441540778523475944706619139394922744328902833875392144658911530830074820", - "19548113127774514328631808547691096362144426239827206966690021428110281506546" - ], - [ - "1870837942477655969123169532603615788122896469891695773961478956740992497097", - "12536105729661705698805725105036536744930776470051238187456307227425796690780" - ], - [ - "21811903352654147452884857281720047789720483752548991551595462057142824037334", - "19021616763967199151052893283384285352200445499680068407023236283004353578353" - ] - ] - ], - "IC": [ - [ - "5645604624116784480262312750033349186912223090668673154853165165224747369512", - "5656337658385597582701340925622307146226708710361427687425735166776477641124", - "1" - ], - [ - "8216930132302312821663833393171053651364962198587857550991047765311607638330", - "19934865864074163318938688021560358348660709566570123384268356491416384822148", - "1" - ], - [ - "11046959016591768534564223076484566731774575511709349452804727872479525392631", - "9401797690410912638766111919371607085248054251975419812613989999345815833269", - "1" - ], - [ - "13216594148914395028254776738842380005944817065680915990743659996725367876414", - "11541283802841111343960351782994043892623551381569479006737253908665900144087", - "1" - ], - [ - "6957074593219251760608960101283708711892008557897337713430173510328411964571", - "21673833055087220750009279957462375662312260098732685145862504142183400549467", - "1" - ], - [ - "20795071270535109448604057031148356571036039566776607847840379441839742201050", - "21654952744643117202636583766828639581880877547772465264383291983528268115687", - "1" - ], - [ - "19143058772755719660075704757531991493801758701561469885274062297246796623789", - "3996020163280925980543600106196205910576345230982361007978823537163123181007", - "1" - ] - ] -} \ No newline at end of file diff --git a/rln/resources/tree_height_20/rln.wasm b/rln/resources/tree_height_20/rln.wasm index 04aaeef7..4f3f8973 100644 Binary files a/rln/resources/tree_height_20/rln.wasm and b/rln/resources/tree_height_20/rln.wasm differ diff --git a/rln/resources/tree_height_20/rln_final.zkey b/rln/resources/tree_height_20/rln_final.zkey index c6cc7d49..46489a11 100644 Binary files a/rln/resources/tree_height_20/rln_final.zkey and b/rln/resources/tree_height_20/rln_final.zkey differ diff --git a/rln/resources/tree_height_20/verification_key.json b/rln/resources/tree_height_20/verification_key.json index 5974ffb0..162e3033 100644 --- a/rln/resources/tree_height_20/verification_key.json +++ b/rln/resources/tree_height_20/verification_key.json @@ -1,20 +1,20 @@ { "protocol": "groth16", "curve": "bn128", - "nPublic": 6, + "nPublic": 5, "vk_alpha_1": [ - "20124996762962216725442980738609010303800849578410091356605067053491763969391", - "9118593021526896828671519912099489027245924097793322973632351264852174143923", + "20491192805390485299153009773594534940189261866228447918068658471970481763042", + "9383485363053290200918347156157836566562967994039712273449902621266178545958", "1" ], "vk_beta_2": [ [ - "4693952934005375501364248788849686435240706020501681709396105298107971354382", - "14346958885444710485362620645446987998958218205939139994511461437152241966681" + "6375614351688725206403948262868962793625744043794305715222011528459656738731", + "4252822878758300859123897981450591353533073413197771768651442665752259397132" ], [ - "16851772916911573982706166384196538392731905827088356034885868448550849804972", - "823612331030938060799959717749043047845343400798220427319188951998582076532" + "10505242626370262277552901082094356697409835680220590971873171140371331206856", + "21847035105528745403288232691147584728191162732299865338377159692350059136679" ], [ "1", @@ -37,12 +37,12 @@ ], "vk_delta_2": [ [ - "8353516066399360694538747105302262515182301251524941126222712285088022964076", - "9329524012539638256356482961742014315122377605267454801030953882967973561832" + "17077735495685170943380938230836408503627170115414840315502244846025577589191", + "14030085636943255545683322474441991939484590437387381169642530788494152024614" ], [ - "16805391589556134376869247619848130874761233086443465978238468412168162326401", - "10111259694977636294287802909665108497237922060047080343914303287629927847739" + "11568745146423307387256571230823432454624378106569286849514884592874522611163", + "1838524899938769516485895655063198583192139511330418290063560641219523306282" ], [ "1", @@ -52,67 +52,62 @@ "vk_alphabeta_12": [ [ [ - "12608968655665301215455851857466367636344427685631271961542642719683786103711", - "9849575605876329747382930567422916152871921500826003490242628251047652318086" + "2029413683389138792403550203267699914886160938906632433982220835551125967885", + "21072700047562757817161031222997517981543347628379360635925549008442030252106" ], [ - "6322029441245076030714726551623552073612922718416871603535535085523083939021", - "8700115492541474338049149013125102281865518624059015445617546140629435818912" + "5940354580057074848093997050200682056184807770593307860589430076672439820312", + "12156638873931618554171829126792193045421052652279363021382169897324752428276" ], [ - "10674973475340072635573101639867487770811074181475255667220644196793546640210", - "2926286967251299230490668407790788696102889214647256022788211245826267484824" + "7898200236362823042373859371574133993780991612861777490112507062703164551277", + "7074218545237549455313236346927434013100842096812539264420499035217050630853" ] ], [ [ - "9660441540778523475944706619139394922744328902833875392144658911530830074820", - "19548113127774514328631808547691096362144426239827206966690021428110281506546" + "7077479683546002997211712695946002074877511277312570035766170199895071832130", + "10093483419865920389913245021038182291233451549023025229112148274109565435465" ], [ - "1870837942477655969123169532603615788122896469891695773961478956740992497097", - "12536105729661705698805725105036536744930776470051238187456307227425796690780" + "4595479056700221319381530156280926371456704509942304414423590385166031118820", + "19831328484489333784475432780421641293929726139240675179672856274388269393268" ], [ - "21811903352654147452884857281720047789720483752548991551595462057142824037334", - "19021616763967199151052893283384285352200445499680068407023236283004353578353" + "11934129596455521040620786944827826205713621633706285934057045369193958244500", + "8037395052364110730298837004334506829870972346962140206007064471173334027475" ] ] ], "IC": [ [ - "11992897507809711711025355300535923222599547639134311050809253678876341466909", - "17181525095924075896332561978747020491074338784673526378866503154966799128110", + "4920513730204767532050733107749276406754520419375654722016092399980613788208", + "10950491564509418434657706642388934308456795265036074733953533582377584967294", "1" ], [ - "17018665030246167677911144513385572506766200776123272044534328594850561667818", - "18601114175490465275436712413925513066546725461375425769709566180981674884464", + "6815064660695497986531118446154820702646540722664044216580897159556261271171", + "17838140936832571103329556013529166877877534025488014783346458943575275015438", "1" ], [ - "18799470100699658367834559797874857804183288553462108031963980039244731716542", - "13064227487174191981628537974951887429496059857753101852163607049188825592007", + "16364982450206976302246609763791333525052810246590359380676749324389440643932", + "17092624338100676284548565502349491320314889021833923882585524649862570629227", "1" ], [ - "17432501889058124609368103715904104425610382063762621017593209214189134571156", - "13406815149699834788256141097399354592751313348962590382887503595131085938635", + "3679639231485547795420532910726924727560917141402837495597760107842698404034", + "16213191511474848247596810551723578773353083440353745908057321946068926848382", "1" ], [ - "10320964835612716439094703312987075811498239445882526576970512041988148264481", - "9024164961646353611176283204118089412001502110138072989569118393359029324867", + "9215428431027260354679105025212521481930206886203677270216204485256690813172", + "934602510541226149881779979217731465262250233587980565969044391353665291792", "1" ], [ - "718355081067365548229685160476620267257521491773976402837645005858953849298", - "14635482993933988261008156660773180150752190597753512086153001683711587601974", - "1" - ], - [ - "11777720285956632126519898515392071627539405001940313098390150593689568177535", - "8483603647274280691250972408211651407952870456587066148445913156086740744515", + "8935861545794299876685457331391349387048184820319250771243971382360441890897", + "4993459033694759724715904486381952906869986989682015547152342336961693234616", "1" ] ] diff --git a/rln/resources/tree_height_32/rln.wasm b/rln/resources/tree_height_32/rln.wasm new file mode 100644 index 00000000..94901cb2 Binary files /dev/null and b/rln/resources/tree_height_32/rln.wasm differ diff --git a/rln/resources/tree_height_32/rln_final.zkey b/rln/resources/tree_height_32/rln_final.zkey new file mode 100644 index 00000000..44e08f92 Binary files /dev/null and b/rln/resources/tree_height_32/rln_final.zkey differ diff --git a/rln/resources/tree_height_32/verification_key.json b/rln/resources/tree_height_32/verification_key.json new file mode 100644 index 00000000..67877066 --- /dev/null +++ b/rln/resources/tree_height_32/verification_key.json @@ -0,0 +1,114 @@ +{ + "protocol": "groth16", + "curve": "bn128", + "nPublic": 5, + "vk_alpha_1": [ + "20491192805390485299153009773594534940189261866228447918068658471970481763042", + "9383485363053290200918347156157836566562967994039712273449902621266178545958", + "1" + ], + "vk_beta_2": [ + [ + "6375614351688725206403948262868962793625744043794305715222011528459656738731", + "4252822878758300859123897981450591353533073413197771768651442665752259397132" + ], + [ + "10505242626370262277552901082094356697409835680220590971873171140371331206856", + "21847035105528745403288232691147584728191162732299865338377159692350059136679" + ], + [ + "1", + "0" + ] + ], + "vk_gamma_2": [ + [ + "10857046999023057135944570762232829481370756359578518086990519993285655852781", + "11559732032986387107991004021392285783925812861821192530917403151452391805634" + ], + [ + "8495653923123431417604973247489272438418190587263600148770280649306958101930", + "4082367875863433681332203403145435568316851327593401208105741076214120093531" + ], + [ + "1", + "0" + ] + ], + "vk_delta_2": [ + [ + "3689226096868373144622340732612563195789744807442014147637039988348252818659", + "18947459102520510468597269280688700807407684209892273827108603062925288762423" + ], + [ + "5816405977664254142436796931495067997250259145480168934320978750042633353708", + "14555486789839131710516067578112557185806110684461247253491378577062852578892" + ], + [ + "1", + "0" + ] + ], + "vk_alphabeta_12": [ + [ + [ + "2029413683389138792403550203267699914886160938906632433982220835551125967885", + "21072700047562757817161031222997517981543347628379360635925549008442030252106" + ], + [ + "5940354580057074848093997050200682056184807770593307860589430076672439820312", + "12156638873931618554171829126792193045421052652279363021382169897324752428276" + ], + [ + "7898200236362823042373859371574133993780991612861777490112507062703164551277", + "7074218545237549455313236346927434013100842096812539264420499035217050630853" + ] + ], + [ + [ + "7077479683546002997211712695946002074877511277312570035766170199895071832130", + "10093483419865920389913245021038182291233451549023025229112148274109565435465" + ], + [ + "4595479056700221319381530156280926371456704509942304414423590385166031118820", + "19831328484489333784475432780421641293929726139240675179672856274388269393268" + ], + [ + "11934129596455521040620786944827826205713621633706285934057045369193958244500", + "8037395052364110730298837004334506829870972346962140206007064471173334027475" + ] + ] + ], + "IC": [ + [ + "5412646265162057015134786739992128493053406364679846617542694915593022919217", + "9665511386935901867415947590751330959748921059696950821222365265700369811120", + "1" + ], + [ + "4294362651275803035824711662252687124584574009834787359330648404293309808795", + "1861758671717754835450145961645465880215655915164196594175485865489885224285", + "1" + ], + [ + "1911114017568107170522785254288953144010421698038439931935418407428234018676", + "13761363892532562822351086117281964648116890138564516558345965908415019790129", + "1" + ], + [ + "16312980235585837964428386585067529342038135099260965575497230302984635878053", + "20286500347141875536561618770383759234192052027362539966911091298688849002783", + "1" + ], + [ + "21038649368092225315431823433752123495654049075935052064397443455654061176031", + "6976971039866104284556300526186000690370678593992968176463280189048347216392", + "1" + ], + [ + "971745799362951123575710699973701411260115357326598060711339429906895409324", + "12959821343398475313407440786226277845673045139874184400082186049649123071798", + "1" + ] + ] +} \ No newline at end of file diff --git a/rln/src/circuit.rs b/rln/src/circuit.rs index 22e75922..de7b29c0 100644 --- a/rln/src/circuit.rs +++ b/rln/src/circuit.rs @@ -30,12 +30,11 @@ const VK_FILENAME: &str = "verification_key.json"; const WASM_FILENAME: &str = "rln.wasm"; // These parameters are used for tests -// Note that the circuit and keys in TEST_RESOURCES_FOLDER are compiled for Merkle trees of height 15, 19 and 20 +// Note that the circuit and keys in TEST_RESOURCES_FOLDER are compiled for Merkle trees of height 20 & 32 // Changing these parameters to other values than these defaults will cause zkSNARK proof verification to fail -pub const TEST_PARAMETERS_INDEX: usize = 2; -pub const TEST_TREE_HEIGHT: usize = [15, 19, 20][TEST_PARAMETERS_INDEX]; -pub const TEST_RESOURCES_FOLDER: &str = - ["tree_height_15", "tree_height_19", "tree_height_20"][TEST_PARAMETERS_INDEX]; +pub const TEST_PARAMETERS_INDEX: usize = 0; +pub const TEST_TREE_HEIGHT: usize = [20, 32][TEST_PARAMETERS_INDEX]; +pub const TEST_RESOURCES_FOLDER: &str = ["tree_height_20", "tree_height_32"][TEST_PARAMETERS_INDEX]; #[cfg(not(target_arch = "wasm32"))] static RESOURCES_DIR: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/resources"); diff --git a/rln/tests/public.rs b/rln/tests/public.rs index d80b36e3..0c593316 100644 --- a/rln/tests/public.rs +++ b/rln/tests/public.rs @@ -35,25 +35,16 @@ mod test { rln.get_root(&mut buffer).unwrap(); let (root, _) = bytes_le_to_fr(&buffer.into_inner()); - if TEST_TREE_HEIGHT == 15 { - assert_eq!( - root, - str_to_fr( - "0x1984f2e01184aef5cb974640898a5f5c25556554e2b06d99d4841badb8b198cd", - 16 - ) - .unwrap() - ); - } else if TEST_TREE_HEIGHT == 19 { + if TEST_TREE_HEIGHT == 20 { assert_eq!( root, str_to_fr( - "0x219ceb53f2b1b7a6cf74e80d50d44d68ecb4a53c6cc65b25593c8d56343fb1fe", + "0x21947ffd0bce0c385f876e7c97d6a42eec5b1fe935aab2f01c1f8a8cbcc356d2", 16 ) .unwrap() ); - } else if TEST_TREE_HEIGHT == 20 { + } else if TEST_TREE_HEIGHT == 32 { assert_eq!( root, str_to_fr( @@ -155,7 +146,7 @@ mod test { vec![1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; // We add the remaining elements for the case TEST_TREE_HEIGHT = 20 - if TEST_TREE_HEIGHT == 19 || TEST_TREE_HEIGHT == 20 { + if TEST_TREE_HEIGHT == 20 || TEST_TREE_HEIGHT == 32 { expected_path_elements.append(&mut vec![ str_to_fr( "0x22f98aa9ce704152ac17354914ad73ed1167ae6596af510aa5b3649325e06c92", diff --git a/rln/vendor/rln b/rln/vendor/rln deleted file mode 160000 index fc86ad15..00000000 --- a/rln/vendor/rln +++ /dev/null @@ -1 +0,0 @@ -Subproject commit fc86ad156ac55b7f805b82ff98501e4eb567bcef