diff --git a/Cargo.lock b/Cargo.lock index 492e8bd..3625aef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,264 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "ahash" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a824f2aa7e75a0c98c5a504fceb80649e9c35265d44525b5f94de4771a395cd" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + +[[package]] +name = "ark-bls12-377" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc41c02c0d18a226947ee9ee023b1d957bdb6a68fc22ac296722935a9fef423c" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-std", +] + +[[package]] +name = "ark-bls12-381" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65be532f9dd1e98ad0150b037276cde464c6f371059e6dd02c0222395761f6aa" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-std", +] + +[[package]] +name = "ark-crypto-primitives" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff773c0ef8c655c98071d3026a63950798a66b2f45baef22d8334c1756f1bd18" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-nonnative-field", + "ark-r1cs-std", + "ark-relations", + "ark-serialize", + "ark-snark", + "ark-std", + "blake2", + "derivative", + "digest", + "rayon", + "tracing", +] + +[[package]] +name = "ark-ec" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dea978406c4b1ca13c2db2373b05cc55429c3575b8b21f1b9ee859aa5b03dd42" +dependencies = [ + "ark-ff", + "ark-serialize", + "ark-std", + "derivative", + "num-traits", + "rayon", + "zeroize", +] + +[[package]] +name = "ark-ff" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b3235cc41ee7a12aaaf2c575a2ad7b46713a8a50bda2fc3b003a04845c05dd6" +dependencies = [ + "ark-ff-asm", + "ark-ff-macros", + "ark-serialize", + "ark-std", + "derivative", + "num-bigint", + "num-traits", + "paste", + "rayon", + "rustc_version 0.3.3", + "zeroize", +] + +[[package]] +name = "ark-ff-asm" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db02d390bf6643fb404d3d22d31aee1c4bc4459600aef9113833d17e786c6e44" +dependencies = [ + "quote", + "syn 1.0.77", +] + +[[package]] +name = "ark-ff-macros" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fd794a08ccb318058009eefdf15bcaaaaf6f8161eb3345f907222bac38b20" +dependencies = [ + "num-bigint", + "num-traits", + "quote", + "syn 1.0.77", +] + +[[package]] +name = "ark-groth16" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38f8fff7468e947130b5caf9bdd27de8b913cf30e15104b4f0cd301726b3d897" +dependencies = [ + "ark-crypto-primitives", + "ark-ec", + "ark-ff", + "ark-poly", + "ark-relations", + "ark-serialize", + "ark-std", + "rayon", +] + +[[package]] +name = "ark-nonnative-field" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "440ad4569974910adbeb84422b7e622b79e08d27142afd113785b7fcfb446186" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-r1cs-std", + "ark-relations", + "ark-std", + "derivative", + "num-bigint", + "num-integer", + "num-traits", + "tracing", +] + +[[package]] +name = "ark-poly" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b0f78f47537c2f15706db7e98fe64cc1711dbf9def81218194e17239e53e5aa" +dependencies = [ + "ark-ff", + "ark-serialize", + "ark-std", + "derivative", + "hashbrown", + "rayon", +] + +[[package]] +name = "ark-r1cs-std" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22e8fdacb1931f238a0d866ced1e916a49d36de832fd8b83dc916b718ae72893" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-relations", + "ark-std", + "derivative", + "num-bigint", + "num-traits", + "tracing", +] + +[[package]] +name = "ark-relations" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cba4c1c99792a6834bd97f7fd76578ec2cd58d2afc5139a17e1d1bec65b38f6" +dependencies = [ + "ark-ff", + "ark-std", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "ark-serialize" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d6c2b318ee6e10f8c2853e73a83adc0ccb88995aa978d8a3408d492ab2ee671" +dependencies = [ + "ark-serialize-derive", + "ark-std", + "digest", +] + +[[package]] +name = "ark-serialize-derive" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dd4e5f0bf8285d5ed538d27fab7411f3e297908fd93c62195de8bee3f199e82" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.77", +] + +[[package]] +name = "ark-snark" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc3dff1a5f67a9c0b34df32b079752d8dd17f1e9d06253da0453db6c1b7cc8a" +dependencies = [ + "ark-ff", + "ark-relations", + "ark-std", +] + +[[package]] +name = "ark-std" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1df2c09229cbc5a028b1d70e00fdb2acee28b1055dfb5ca73eea49c5a25c4e7c" +dependencies = [ + "num-traits", + "rand", + "rayon", +] + +[[package]] +name = "arkworks-mimc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1754f52e36264567503495be341d76093a0f4201a8887d6c54eb8d6351696583" +dependencies = [ + "ark-crypto-primitives", + "ark-ff", + "ark-r1cs-std", + "ark-relations", + "ark-std", +] + [[package]] name = "async-stream" version = "0.3.2" @@ -20,7 +278,7 @@ checksum = "648ed8c8d2ce5409ccd57453d9d1b214b342a0d69376a6feda1fd6cae3299308" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.77", ] [[package]] @@ -31,7 +289,7 @@ checksum = "44318e776df68115a881de9a8fd1b9e53368d7a4a5ce4cc48517da3393233a5e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.77", ] [[package]] @@ -60,6 +318,21 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +[[package]] +name = "backtrace" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + [[package]] name = "base-x" version = "0.2.8" @@ -120,6 +393,17 @@ dependencies = [ "wyz 0.5.0", ] +[[package]] +name = "blake2" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a4e37d16930f5459780f5621038b6382b9bb37c19016f39fb6b5808d831f174" +dependencies = [ + "crypto-mac", + "digest", + "opaque-debug", +] + [[package]] name = "block-buffer" version = "0.9.0" @@ -257,6 +541,16 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "crypto-mac" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" +dependencies = [ + "generic-array", + "subtle", +] + [[package]] name = "darling" version = "0.13.4" @@ -278,7 +572,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn", + "syn 1.0.77", ] [[package]] @@ -289,7 +583,18 @@ checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" dependencies = [ "darling_core", "quote", - "syn", + "syn 1.0.77", +] + +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.77", ] [[package]] @@ -322,7 +627,7 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics", "quote", - "syn", + "syn 1.0.77", ] [[package]] @@ -487,7 +792,7 @@ dependencies = [ "proc-macro-hack", "proc-macro2", "quote", - "syn", + "syn 1.0.77", ] [[package]] @@ -554,9 +859,15 @@ checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" dependencies = [ "cfg-if", "libc", - "wasi", + "wasi 0.10.2+wasi-snapshot-preview1", ] +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + [[package]] name = "glob" version = "0.3.0" @@ -599,6 +910,9 @@ name = "hashbrown" version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +dependencies = [ + "ahash", +] [[package]] name = "hermit-abi" @@ -660,7 +974,7 @@ dependencies = [ "httpdate", "itoa 0.4.8", "pin-project-lite", - "socket2", + "socket2 0.4.2", "tokio", "tower-service", "tracing", @@ -758,9 +1072,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.103" +version = "0.2.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6" +checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" [[package]] name = "lock_api" @@ -821,25 +1135,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" [[package]] -name = "mio" -version = "0.7.13" +name = "miniz_oxide" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c2bdb6314ec10835cd3293dd268473a835c02b7b352e788be788b3c6ca6bb16" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" dependencies = [ - "libc", - "log", - "miow", - "ntapi", - "winapi", + "adler", ] [[package]] -name = "miow" -version = "0.3.7" +name = "mio" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" +checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" dependencies = [ - "winapi", + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", + "windows-sys 0.48.0", ] [[package]] @@ -881,12 +1193,33 @@ dependencies = [ ] [[package]] -name = "ntapi" -version = "0.3.6" +name = "num-bigint" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" +checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" dependencies = [ - "winapi", + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +dependencies = [ + "autocfg", ] [[package]] @@ -899,6 +1232,15 @@ dependencies = [ "libc", ] +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + [[package]] name = "okapi" version = "0.7.0-rc.1" @@ -913,9 +1255,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.8.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "opaque-debug" @@ -946,7 +1288,7 @@ checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.77", ] [[package]] @@ -972,6 +1314,17 @@ dependencies = [ name = "ophe" version = "0.1.0" dependencies = [ + "ark-bls12-377", + "ark-bls12-381", + "ark-crypto-primitives", + "ark-ec", + "ark-ff", + "ark-groth16", + "ark-r1cs-std", + "ark-relations", + "ark-serialize", + "ark-std", + "arkworks-mimc", "base64", "bencher", "bit-vec", @@ -990,7 +1343,9 @@ dependencies = [ "serde_json", "serde_with", "sha2", + "subtle", "time", + "tokio", ] [[package]] @@ -1027,6 +1382,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "paste" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" + [[package]] name = "pear" version = "0.2.3" @@ -1047,7 +1408,7 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics", "quote", - "syn", + "syn 1.0.77", ] [[package]] @@ -1057,10 +1418,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] -name = "pin-project-lite" -version = "0.2.7" +name = "pest" +version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" +checksum = "1f200d8d83c44a45b21764d1916299752ca035d15ecd46faca3e9a2a2bf6ad06" +dependencies = [ + "memchr", + "thiserror", + "ucd-trie", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] name = "pin-utils" @@ -1094,11 +1466,11 @@ checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" [[package]] name = "proc-macro2" -version = "1.0.29" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] @@ -1109,16 +1481,16 @@ checksum = "4bf29726d67464d49fa6224a1d07936a8c08bb3fba727c7493f6cf1616fdaada" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.77", "version_check", "yansi", ] [[package]] name = "quote" -version = "1.0.9" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -1226,7 +1598,7 @@ checksum = "4c38e3aecd2b21cb3959637b883bb3714bc7e43f0268b9a29d3743ee3e55cdd2" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.77", ] [[package]] @@ -1324,7 +1696,7 @@ dependencies = [ "proc-macro2", "quote", "rocket_http", - "syn", + "syn 1.0.77", "unicode-xid", ] @@ -1382,16 +1754,31 @@ dependencies = [ "proc-macro2", "quote", "rocket_http", - "syn", + "syn 1.0.77", ] +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + [[package]] name = "rustc_version" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" dependencies = [ - "semver", + "semver 0.9.0", +] + +[[package]] +name = "rustc_version" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" +dependencies = [ + "semver 0.11.0", ] [[package]] @@ -1413,7 +1800,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" dependencies = [ "lazy_static", - "windows-sys", + "windows-sys 0.36.1", ] [[package]] @@ -1438,7 +1825,7 @@ dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn", + "syn 1.0.77", ] [[package]] @@ -1482,7 +1869,16 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" dependencies = [ - "semver-parser", + "semver-parser 0.7.0", +] + +[[package]] +name = "semver" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" +dependencies = [ + "semver-parser 0.10.2", ] [[package]] @@ -1491,6 +1887,15 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" +[[package]] +name = "semver-parser" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" +dependencies = [ + "pest", +] + [[package]] name = "serde" version = "1.0.130" @@ -1508,7 +1913,7 @@ checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.77", ] [[package]] @@ -1519,7 +1924,7 @@ checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.77", ] [[package]] @@ -1565,7 +1970,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn", + "syn 1.0.77", ] [[package]] @@ -1618,6 +2023,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "socket2" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" +dependencies = [ + "libc", + "windows-sys 0.48.0", +] + [[package]] name = "spin" version = "0.9.2" @@ -1658,7 +2073,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" dependencies = [ "discard", - "rustc_version", + "rustc_version 0.2.3", "stdweb-derive", "stdweb-internal-macros", "stdweb-internal-runtime", @@ -1675,7 +2090,7 @@ dependencies = [ "quote", "serde", "serde_derive", - "syn", + "syn 1.0.77", ] [[package]] @@ -1691,7 +2106,7 @@ dependencies = [ "serde_derive", "serde_json", "sha1", - "syn", + "syn 1.0.77", ] [[package]] @@ -1723,6 +2138,17 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "syn" +version = "2.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "tap" version = "1.0.1" @@ -1743,6 +2169,26 @@ dependencies = [ "winapi", ] +[[package]] +name = "thiserror" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "time" version = "0.2.27" @@ -1778,7 +2224,7 @@ dependencies = [ "proc-macro2", "quote", "standback", - "syn", + "syn 1.0.77", ] [[package]] @@ -1798,32 +2244,31 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.12.0" +version = "1.35.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2c2416fdedca8443ae44b4527de1ea633af61d8f7169ffa6e72c5b53d24efcc" +checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104" dependencies = [ - "autocfg", + "backtrace", "bytes", "libc", - "memchr", "mio", "num_cpus", - "once_cell", "pin-project-lite", "signal-hook-registry", + "socket2 0.5.5", "tokio-macros", - "winapi", + "windows-sys 0.48.0", ] [[package]] name = "tokio-macros" -version = "1.4.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "154794c8f499c2619acd19e839294703e9e32e7630ef5f46ea80d4ef0fbee5eb" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.48", ] [[package]] @@ -1884,9 +2329,21 @@ checksum = "84f96e095c0c82419687c20ddf5cb3eadb61f4e1405923c9dc8e53a1adacbda8" dependencies = [ "cfg-if", "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "tracing-core" version = "0.1.21" @@ -1896,6 +2353,15 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "tracing-subscriber" +version = "0.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e0d2eaa99c3c2e41547cfa109e910a68ea03823cccad4a0525dcbc9b01e8c71" +dependencies = [ + "tracing-core", +] + [[package]] name = "try-lock" version = "0.2.3" @@ -1927,6 +2393,12 @@ dependencies = [ "serde", ] +[[package]] +name = "ucd-trie" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" + [[package]] name = "uncased" version = "0.9.6" @@ -1949,6 +2421,12 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + [[package]] name = "unicode-normalization" version = "0.1.19" @@ -1984,9 +2462,9 @@ checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "version_check" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "want" @@ -2004,6 +2482,12 @@ version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + [[package]] name = "wasm-bindgen" version = "0.2.80" @@ -2025,7 +2509,7 @@ dependencies = [ "log", "proc-macro2", "quote", - "syn", + "syn 1.0.77", "wasm-bindgen-shared", ] @@ -2059,7 +2543,7 @@ checksum = "99ec0dc7a4756fffc231aab1b9f2f578d23cd391390ab27f952ae0c9b3ece20b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.77", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2108,43 +2592,109 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" dependencies = [ - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_msvc", + "windows_aarch64_msvc 0.36.1", + "windows_i686_gnu 0.36.1", + "windows_i686_msvc 0.36.1", + "windows_x86_64_gnu 0.36.1", + "windows_x86_64_msvc 0.36.1", ] +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + [[package]] name = "windows_aarch64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + [[package]] name = "windows_i686_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + [[package]] name = "windows_i686_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + [[package]] name = "windows_x86_64_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + [[package]] name = "windows_x86_64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + [[package]] name = "winreg" version = "0.7.0" @@ -2177,3 +2727,23 @@ name = "yansi" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fc79f4a1e39857fc00c3f662cbf2651c771f00e9c15fe2abc341806bd46bd71" + +[[package]] +name = "zeroize" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] diff --git a/Cargo.toml b/Cargo.toml index 86bcfe5..a939e1e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,21 @@ futures = "*" reqwest ={ version = "*", features = ["json"]} rocket_okapi = { version = "0.8.0-alpha-1", features = ["swagger", "rapidoc"] } +arkworks-mimc = { version = "0.3.0", features = ["mimc-7-91-bls12-381","r1cs"] } +ark-ff = { version = "^0.3.0", default-features = false } +ark-bls12-381 = "0.3.0" +ark-bls12-377 = "0.3.0" +ark-crypto-primitives = "0.3.0" +ark-std = "0.3.0" +ark-relations = "0.3.0" +ark-r1cs-std = "0.3.0" +ark-groth16 = "0.3.0" +ark-serialize = "0.3.0" +ark-ec = "0.3.0" +subtle = "*" + +# Fixes compilation on windows +tokio = "1.28.0" [[bin]] name = "cryptoservice" diff --git a/src/core.rs b/src/core.rs index 60b41af..138d424 100644 --- a/src/core.rs +++ b/src/core.rs @@ -1,3 +1,6 @@ +use ark_bls12_381::Bls12_381; +use ark_groth16::PreparedVerifyingKey; +use ark_groth16::ProvingKey; use bls12_381::*; use group::Group; use crate::utils; @@ -28,35 +31,43 @@ pub struct ServerState{ r: Scalar, pub n: Scalar, p: G2Projective, - pw: String, + ps: Scalar, + pw: String } impl ServerState { - fn new(username: &String, password: &String) -> ServerState{ + fn new(username: &String, password: &String,pk: &ProvingKey) -> (ServerState,Vec){ let r = utils::random_scalar(); let n = utils::random_scalar(); - - let username = username.to_owned(); - let to_be_hashed = username + password; - let tempr = utils::hash_string_to_scalar(to_be_hashed); - let p = G2Affine::generator() * tempr * r; - ServerState{r,n,p,pw: password.to_owned()} + + let (hash_scalar,hash_proof) = proofs::generate_hash_proof(username, password, &n, &r, pk); + let p = G2Affine::generator() * hash_scalar; + + // let username = username.to_owned(); + // let to_be_hashed = username + password; + // let tempr = utils::hash_string_to_scalar(to_be_hashed); + // let p = G2Affine::generator() * tempr * r; + + (ServerState{r,n,p,ps:hash_scalar,pw: password.to_owned()},hash_proof) } - fn from_nonce(username: &String, password: &String, nonce: &Scalar) -> ServerState{ + fn from_nonce(username: &String, password: &String, nonce: &Scalar,pk: &ProvingKey) -> (ServerState,Vec){ let r = utils::random_scalar(); - - let username = username.to_owned(); - let to_be_hashed = username + password; - let tempr = utils::hash_string_to_scalar(to_be_hashed); - let p = G2Affine::generator() * tempr * r; - ServerState{r,n: nonce.clone(),p,pw: password.to_owned()} + let (hash_scalar,hash_proof) = proofs::generate_hash_proof(username, password, &nonce, &r, pk); + let p = G2Affine::generator() * hash_scalar; + + // let username = username.to_owned(); + // let to_be_hashed = username + password; + // let tempr = utils::hash_string_to_scalar(to_be_hashed); + // let p = G2Affine::generator() * tempr * r; + + (ServerState{r,n: nonce.clone(),p,ps:hash_scalar,pw: password.to_owned()},hash_proof) } } #[serde_as] -#[derive(Serialize, Deserialize, JsonSchema,Clone,Copy,Debug)] +#[derive(Serialize, Deserialize, JsonSchema,Clone,Debug)] pub struct RatelimiterRequest{ #[serde_as(as = "serializers::SerializeScalar")] #[schemars(with = "String")] @@ -64,6 +75,12 @@ pub struct RatelimiterRequest{ #[serde_as(as = "serializers::SerializeG2")] #[schemars(with = "String")] p: G2Projective, + #[serde_as(as = "serializers::SerializeScalar")] + #[schemars(with = "String")] + ps: Scalar, + #[serde_as(as = "serde_with::base64::Base64")] + #[schemars(with = "String")] + hash_proof: Vec } #[serde_as] @@ -118,28 +135,42 @@ pub struct SetKeyHelper{ } -pub fn phe_init(username: &String, password: &String) -> (ServerState,RatelimiterRequest){ - let ss = ServerState::new(username,password); - let rr = RatelimiterRequest{n:ss.n,p:ss.p}; +pub fn phe_init(username: &String, password: &String,pk: &ProvingKey) -> (ServerState,RatelimiterRequest){ + let (ss,hash_proof) = ServerState::new(username,password,pk); + let rr = RatelimiterRequest{n:ss.n,p:ss.p,hash_proof,ps:ss.ps}; return (ss,rr) } -pub fn phe_init_decrypt(username: &String, password: &String,n: &Scalar) -> (ServerState,RatelimiterRequest){ - let ss = ServerState::from_nonce(username,password,n); - let rr = RatelimiterRequest{n:ss.n,p:ss.p}; +pub fn phe_init_decrypt(username: &String, password: &String,n: &Scalar,pk: &ProvingKey) -> (ServerState,RatelimiterRequest){ + let (ss,hash_proof) = ServerState::from_nonce(username,password,n,pk); + let rr = RatelimiterRequest{n:ss.n,p:ss.p,hash_proof,ps:ss.ps}; return (ss,rr) } -pub fn phe_ratelimiter(private_key: &Scalar, request: &RatelimiterRequest,pp: &PublicParameters) -> RatelimiterResponse { + +pub fn phe_ratelimiter(private_key: &Scalar, request: &RatelimiterRequest,pp: &PublicParameters,pvk: &PreparedVerifyingKey) -> Result { + // check if request.p = G2Affine::generator() * hash_proof + if (G2Affine::generator() * request.ps) != request.p{ + return Err("Invalid hash proof. Hash scalar and Point not matching.".to_string()); + } + + //verify hash proof + let result = proofs::validate_hash_proof(&request.ps,&request.hash_proof,&pvk); + if !result{ + return Err("Invalid hash proof.".to_string()); + } + let n = request.n; let u = pairing(&G1Affine::from(G1Affine::generator() * n) , &G2Affine::from(request.p)); let value = u*private_key; let proof = proofs::SameDLogProofPublic{g:pp.gt_gen,h:u,y1:pp.ratelimiter_public_key,y2:value}.proof(&private_key); - RatelimiterResponse{proof,u:value} + + + Ok(RatelimiterResponse{proof,u:value}) } pub fn phe_enc_finish_t(msg: &Vec,pp: &Vec,response: &Vec,ss:&ServerState,n: i64) -> Result{ @@ -421,12 +452,14 @@ fn test_core_t(n:i64,t:i64){ assert_eq!(pp_key,generator*realkey,"Public keys do not match"); + let (pk,vk,pvk) = proofs::setup_hash_proof(); + let start = Instant::now(); - let (ss,request) = phe_init(&"test".to_string(),&"test".to_string()); + let (ss,request) = phe_init(&"test".to_string(),&"test".to_string(),&pk); println!("{:.2?} phe_init",start.elapsed()); let responses = (0..t as usize).into_par_iter().map(|i|{ - let response = phe_ratelimiter(&rlkeys[i],&request,&pps[i]); + let response = phe_ratelimiter(&rlkeys[i],&request,&pps[i],&pvk).unwrap(); response }).collect::>(); @@ -434,10 +467,10 @@ fn test_core_t(n:i64,t:i64){ let res = phe_enc_finish_t(&msg,&pps,&responses,&ss,n).unwrap(); println!("{:.2?} phe_enc_finish_t",start.elapsed()); - let (ss,request) = phe_init_decrypt(&"test".to_string(),&"test".to_string(),&request.n); + let (ss,request) = phe_init_decrypt(&"test".to_string(),&"test".to_string(),&request.n, &pk); let responses = (0..t as usize).into_par_iter().map(|i|{ - let response = phe_ratelimiter(&rlkeys[i],&request,&pps[i]); + let response = phe_ratelimiter(&rlkeys[i],&request,&pps[i],&pvk).unwrap(); response }).collect::>(); @@ -459,14 +492,16 @@ fn test_core_k() { ratelimiter_public_key: public_key }; + let (pk,vk,pvk) = proofs::setup_hash_proof(); + let start = Instant::now(); - let (ss,request) = phe_init(&"test".to_string(),&"test".to_string()); + let (ss,request) = phe_init(&"test".to_string(),&"test".to_string(),&pk); println!("{:.2?} phe_init",start.elapsed()); - let response = phe_ratelimiter(&key,&request,&pp); + let response = phe_ratelimiter(&key,&request,&pp,&pvk).unwrap(); let start = Instant::now(); for _i in 0..100{ - let response = phe_ratelimiter(&key,&request,&pp); + let response = phe_ratelimiter(&key,&request,&pp,&pvk).unwrap(); } println!("{:.2?} phe_ratelimiter",start.elapsed()/1000); @@ -477,9 +512,9 @@ fn test_core_k() { } println!("{:.2?} phe_enc_finish",start.elapsed()/1000); - let (ss,request) = phe_init_decrypt(&"test".to_string(),&"test".to_string(),&ciphertext.n); + let (ss,request) = phe_init_decrypt(&"test".to_string(),&"test".to_string(),&ciphertext.n, &pk); - let response = phe_ratelimiter(&key,&request,&pp); + let response = phe_ratelimiter(&key,&request,&pp,&pvk).unwrap(); let expected = phe_dec_finish_simple(&ciphertext,&pp,&response,&ss).unwrap(); let start = Instant::now(); diff --git a/src/cryptoservice.rs b/src/cryptoservice.rs index bf6ac65..e982ebb 100644 --- a/src/cryptoservice.rs +++ b/src/cryptoservice.rs @@ -4,9 +4,12 @@ extern crate bls12_381; extern crate rand; use std::sync::RwLock; +use ark_bls12_381::Bls12_381; +use ark_groth16::PreparedVerifyingKey; use bls12_381::pairing; use bls12_381::G2Affine; -use std::sync::Mutex; +use ophe::proofs; +use ophe::proofs::HashProof; use std::sync::Arc; use rocket_okapi::settings::UrlObject; use rocket_okapi::{openapi, openapi_get_routes, rapidoc::*, swagger_ui::*}; @@ -22,23 +25,35 @@ use bls12_381::Scalar; use bls12_381::G1Affine; - fn make_public_parameters(key: Scalar) -> CryptoserviceState{ let generator = pairing(&G1Affine::generator(), &G2Affine::generator()); let public_key = generator * key; let pp = core::PublicParameters{ratelimiter_public_key:public_key,gt_gen:generator}; - CryptoserviceState{key,pp} + + let mut rng = OsRng::default(); + + let test: HashProof = HashProof { + pw_point: None, + nonce_point: None, + random_r: None, + }; + + let (pk, vk,pvk) = proofs::setup_hash_proof(); + + CryptoserviceState{key,pp,hashproof_pvk:pvk} } + struct CryptoserviceState { key: Scalar, pp: core::PublicParameters, + hashproof_pvk: PreparedVerifyingKey, } type CryptoserviceStatePointer = Arc>; - +use rand_core::{RngCore, OsRng}; #[rocket::main] async fn main() { @@ -80,15 +95,14 @@ async fn main() { #[openapi()] #[post("/phe_help",format = "json", data = "")] -fn phe_help(request: Json,c_state: &State) -> Json { +fn phe_help(request: Json,c_state: &State) -> Result,String> { - let (key,pp) = { + let (key,pp,pvk) = { let c_state = c_state.read().unwrap(); - (c_state.key.clone(),c_state.pp.clone()) + (c_state.key.clone(),c_state.pp.clone(),c_state.hashproof_pvk.clone()) }; - - Json(core::phe_ratelimiter(&key,&request,&pp)) + Ok(Json(core::phe_ratelimiter(&key,&request,&pp,&pvk)?)) } #[openapi()] diff --git a/src/lib.rs b/src/lib.rs index e1a3a5a..b668f35 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -mod proofs; +pub mod proofs; pub mod utils; pub mod shamir; pub mod core; diff --git a/src/ophe.rs b/src/ophe.rs index e8e0f84..f1a1999 100644 --- a/src/ophe.rs +++ b/src/ophe.rs @@ -3,11 +3,15 @@ extern crate bls12_381; extern crate rand; +use ark_bls12_381::Bls12_381; +use ark_groth16::PreparedVerifyingKey; +use ark_groth16::ProvingKey; use bls12_381::G2Affine; use bls12_381::Gt; use bls12_381::Scalar; use bls12_381::pairing; use bls12_381::G1Affine; +use ophe::proofs; use rocket::request; use std::time::Duration; use crate::core::EncryptedMessage; @@ -43,6 +47,7 @@ struct OpheState { n: i64, t: i64, pk: Gt, + hash_proof_vk: ProvingKey, } #[derive(Serialize,Deserialize,JsonSchema)] @@ -77,7 +82,7 @@ fn serialize_failed(_req: &Request) -> String { #[rocket::main] async fn main() { - let cryptoservice_urls = vec!["http://localhost:9001","http://localhost:9002","http://localhost:9003"]; + let cryptoservice_urls = vec!["http://localhost:9001","http://localhost:9002"]; let n = cryptoservice_urls.len(); let t = n; let rl_key = ophe::utils::random_scalar(); @@ -102,7 +107,9 @@ async fn main() { assert_eq!(pp_key,rl_public_key,"Public keys do not match"); - let o_state = OpheState{pps,n: n as i64,t: t as i64, pk: pp_key}; + let hash_proof_setup = proofs::setup_hash_proof(); + + let o_state = OpheState{pps,n: n as i64,t: t as i64, pk: pp_key, hash_proof_vk: hash_proof_setup.0}; println!("Received public parameters from crytoservice"); @@ -143,7 +150,7 @@ async fn main() { #[openapi()] #[post("/encrypt",format = "json", data = "")] async fn encrypt(request: Json,o_state: &State) -> Result,(Status, Json)> { - let (ss,request1) = core::phe_init(&request.username,&request.password); + let (ss,request1) = core::phe_init(&request.username,&request.password,&o_state.hash_proof_vk); let mut msg = request.data.clone().into_bytes(); @@ -165,7 +172,7 @@ async fn encrypt(request: Json,o_state: &State) -> Re #[openapi()] #[post("/decrypt",format = "json", data = "")] async fn decrypt(request: Json,o_state: &State) -> Result,(Status, Json)> { - let (ss,request1) = core::phe_init_decrypt(&request.username,&request.password,&request.ciphertext.n); + let (ss,request1) = core::phe_init_decrypt(&request.username,&request.password,&request.ciphertext.n,&o_state.hash_proof_vk); let responses = get_ratelimiter_reponses(&request1,&o_state.pps).await.map_err(|x| {(Status::InternalServerError,Json("Decryption failed: ".to_string()+&x))})?; diff --git a/src/proofs.rs b/src/proofs.rs index 10b9c3d..7b4e640 100644 --- a/src/proofs.rs +++ b/src/proofs.rs @@ -1,23 +1,48 @@ -use bls12_381::*; -use crate::utils; +use std::convert::TryInto; +use std::time::Instant; + use crate::serializers; -use serde::{Deserialize, Serialize}; -use rocket_okapi::okapi::schemars; -use rocket_okapi::okapi::schemars::JsonSchema; -use serde_with::serde_as; +use crate::utils; +use ark_bls12_381::Bls12_381; +use ark_crypto_primitives::CircuitSpecificSetupSNARK; +use ark_crypto_primitives::SNARK; +use ark_ff::BigInteger; +use ark_ff::Fp2; +use ark_ff::Fp384; +use ark_ff::Fp384Parameters; +use ark_groth16::PreparedVerifyingKey; +use ark_groth16::Proof; +use ark_groth16::ProvingKey; +use ark_groth16::VerifyingKey; +use ark_groth16::prepare_verifying_key; +use ark_groth16::Groth16; +use ark_r1cs_std::alloc::AllocationMode; +use ark_r1cs_std::eq::EqGadget; +use ark_r1cs_std::fields::FieldVar; +use ark_relations::lc; +use ark_relations::r1cs::ConstraintSynthesizer; +use ark_relations::r1cs::ConstraintSystem; +use ark_relations::r1cs::ConstraintSystemRef; +use ark_relations::r1cs::SynthesisError; +use ark_serialize::CanonicalSerializeWithFlags; +use arkworks_mimc::constraints::MiMCVar; +use bls12_381::*; #[cfg(test)] use group::Group; - - +use rand_core::OsRng; +use rocket_okapi::okapi::schemars; +use rocket_okapi::okapi::schemars::JsonSchema; +use serde::{Deserialize, Serialize}; +use serde_with::serde_as; pub struct SameDLogProofPublic { - pub g: Gt, - pub h: Gt, - pub y1: Gt, - pub y2: Gt, + pub g: Gt, + pub h: Gt, + pub y1: Gt, + pub y2: Gt, } -impl SameDLogProofPublic{ +impl SameDLogProofPublic { pub fn new(g: Gt, h: Gt, x: Scalar) -> Self { SameDLogProofPublic { g, @@ -27,7 +52,7 @@ impl SameDLogProofPublic{ } } - pub fn proof(&self,x: &Scalar) -> SameDLogProof{ + pub fn proof(&self, x: &Scalar) -> SameDLogProof { let r = utils::random_scalar(); let c = utils::hash_gt_to_scalar(&[&self.g, &self.h, &self.y1, &self.y2]); let t = r - x * c; @@ -39,9 +64,8 @@ impl SameDLogProofPublic{ } } - #[serde_as] -#[derive(Eq,PartialEq,Debug,Serialize,Deserialize,JsonSchema)] +#[derive(Eq, PartialEq, Debug, Serialize, Deserialize, JsonSchema)] pub struct SameDLogProof { #[serde_as(as = "serializers::SerializeGt")] #[schemars(with = "String")] @@ -54,15 +78,13 @@ pub struct SameDLogProof { t: Scalar, } - impl SameDLogProof { - pub fn verify(&self,pp: &SameDLogProofPublic) -> bool{ + pub fn verify(&self, pp: &SameDLogProofPublic) -> bool { let c = utils::hash_gt_to_scalar(&[&pp.g, &pp.h, &pp.y1, &pp.y2]); self.a == (pp.g * self.t) + (pp.y1 * c) && self.b == (pp.h * self.t) + (pp.y2 * c) } } - #[test] fn test_proof_correct() { let x = utils::random_scalar(); @@ -83,7 +105,6 @@ fn test_proof_incorrect() { assert!(!proof.verify(&pp)); } - #[test] fn test_proof_serialize() { let x = utils::random_scalar(); @@ -94,4 +115,355 @@ fn test_proof_serialize() { let serialized = serde_json::to_string(&proof).unwrap(); let proof2: SameDLogProof = serde_json::from_str(&serialized).unwrap(); assert_eq!(proof, proof2); -} \ No newline at end of file +} + +use arkworks_mimc::params::mimc_7_91_bls12_381::{ + MIMC_7_91_BLS12_381_PARAMS, MIMC_7_91_BLS12_381_ROUND_KEYS, +}; +use arkworks_mimc::params::round_keys_contants_to_vec; +use arkworks_mimc::MiMC; +//mimc-7-91-bls12-381 +use ark_bls12_381::Fr; +use ark_bls12_381::Fq; +use ark_ff::Field; +use ark_ff::PrimeField; +use ark_ff::Zero; +use bls12_381::*; + +#[test] +fn test_mimc_hash() { + let mimc = MiMC::::new( + 1, + Fr::zero(), + round_keys_contants_to_vec(&MIMC_7_91_BLS12_381_ROUND_KEYS), + ); + println!( + "mimc hash: {:?}", + mimc.permute_non_feistel(vec![Fr::zero()]) + ); +} + +// nizk for p2,pw,n,r prove that p2 = r * mimc(pw,n) which is g2/str to g2 where p2 is public + +use ark_std; + +use arkworks_mimc::{ + constraints::{MiMCFeistelCRHGadget}, + MiMCFeistelCRH +}; + +use ark_crypto_primitives::{ + crh::{TwoToOneCRH, TwoToOneCRHGadget}, + CRH as CRHTrait, +}; +use ark_ff::to_bytes; + +use ark_r1cs_std::{ + fields::fp::FpVar, + prelude::{AllocVar}, + R1CSVar, ToBytesGadget, +}; + +use ark_serialize::{CanonicalSerialize, CanonicalDeserialize}; +use ark_std::io::{Read, Write}; +use sha2::Digest; +use std::ops::MulAssign; +use ark_serialize::SerializationError; + + +//TODO Type conversion +//TODO add to server +//TODO add to client +//TODO 32 bytes? + +pub fn setup_hash_proof() -> (ProvingKey, VerifyingKey, PreparedVerifyingKey) { + let a = Fr::from(20); // No idea why this is needed // TODO remove once fixed + + let test: HashProof = HashProof { + pw_point: Some(a), + nonce_point: Some(a), + random_r: Some(a), + }; + + let mut rng = OsRng::default(); + let (pk, vk) = Groth16::::setup(test.clone(), &mut rng).unwrap(); + let pvk = prepare_verifying_key::(&vk); + (pk, vk, pvk) +} + +pub fn generate_hash_proof(username: &String, password: &String, nonce: &Scalar,random: &Scalar,pk: &ProvingKey)-> (Scalar,Vec){ + // hash the password and nonce to Fr + let n_fr = Fr::from_le_bytes_mod_order(&nonce.to_bytes()); + //use sha256 + let mut hasher = sha2::Sha256::new(); + hasher.update(username.as_bytes()); + hasher.update(password.as_bytes()); + let hash = hasher.finalize(); + let hash_fr = Fr::from_le_bytes_mod_order(&hash); + // hash the two Fr to Fr + let random_fr = Fr::from_le_bytes_mod_order(&random.to_bytes()); + let mimc = MiMC::::new( + 1, + Fr::zero(), + round_keys_contants_to_vec(&MIMC_7_91_BLS12_381_ROUND_KEYS), + ); + let hashed = as TwoToOneCRH>::evaluate( + &mimc, + &to_bytes!(hash_fr).unwrap(), + &to_bytes!(n_fr).unwrap(), + ).unwrap(); + + let result_fr = random_fr * hashed; + let mut result_vec = Vec::new(); + result_fr.serialize(&mut result_vec).unwrap(); + // convert to &[u8; 32] + let result_arr = result_vec.as_slice().try_into().unwrap(); + let result_scalar = Scalar::from_bytes(result_arr).unwrap(); + let proof = HashProof { + pw_point: Some(hash_fr), + nonce_point: Some(n_fr), + random_r: Some(random_fr), + }; + let proof = Groth16::::prove( + &pk, + proof, + &mut ark_std::test_rng(), + ).unwrap(); + + let mut proof_serialized = Vec::::new(); + proof.serialize(&mut proof_serialized).unwrap(); + + (result_scalar,proof_serialized) +} + +pub fn validate_hash_proof(scalar: &Scalar, proof: &Vec, vk: &PreparedVerifyingKey) -> bool { + match Proof::::deserialize(&proof[..]) { + Ok(proof) => { + let g2_fr = Fr::from_le_bytes_mod_order(&scalar.to_bytes()); + match Groth16::::verify_with_processed_vk(&vk, &[g2_fr], &proof) { + Ok(result) => result, + Err(_) => false, + } + } + Err(_) => false, + } +} + +#[derive(Clone, Debug, PartialEq, Eq, Hash,CanonicalSerialize, CanonicalDeserialize)] +pub struct HashProof { + pub pw_point: Option, + pub nonce_point: Option, + pub random_r: Option, +} + +impl ConstraintSynthesizer for HashProof { + fn generate_constraints(self, cs: ConstraintSystemRef) -> Result<(), SynthesisError> { + + let mimc = MiMC::::new( + 1, + Fr::zero(), + round_keys_contants_to_vec(&MIMC_7_91_BLS12_381_ROUND_KEYS), + ); + + let x_l = self.pw_point.ok_or(SynthesisError::AssignmentMissing)?; + let x_r = self.nonce_point.ok_or(SynthesisError::AssignmentMissing)?; + let c_r = self.random_r.ok_or(SynthesisError::AssignmentMissing)?; + + let x_l_var = FpVar::new_witness(cs.clone(), || Ok(x_l) )?; + let x_r_var = FpVar::new_witness(cs.clone(), || Ok(x_r) )?; + let c_r_var = FpVar::new_witness(cs.clone(), || Ok(c_r) )?; + let k_var = FpVar::new_constant(cs.clone(), &mimc.k)?; + + let round_keys = Vec::>::new_constant(cs.clone(), mimc.round_keys)?; + let mimc_var = MiMCVar::<_, _>::new(1, k_var, round_keys); + + let hashed_var = + as TwoToOneCRHGadget< + MiMCFeistelCRH<_, _>, + _, + >>::evaluate(&mimc_var, &x_l_var.to_bytes()?, &x_r_var.to_bytes()?) + .unwrap(); + + // mult c and hashed_var + let result = FpVar::new_input(cs.clone(), || { + let mut res = c_r_var.value()?; + res.mul_assign(&hashed_var.value()?); + Ok(res) + })?; + + Ok(()) + } +} + + +#[test] +fn test_type_conversion() { + +let usename = String::from("username"); +let password = String::from("password"); +let nonce = utils::random_scalar(); +let random = utils::random_scalar(); +let (pk, vk, pvk) = setup_hash_proof(); +let (sclar1, proof) = generate_hash_proof(&usename, &password, &nonce, &random, &pk); +let res = validate_hash_proof(&sclar1, &proof, &pvk); +assert!(res); +// change g2 and test for inequality +let mut scalar2 = sclar1; +scalar2 *= utils::random_scalar(); +let res = validate_hash_proof(&scalar2, &proof, &pvk); +assert!(!res); +// change proof and test for inequality +let mut proof2 = proof; +proof2[0] = 0; +let res = validate_hash_proof(&sclar1, &proof2, &pvk); +assert!(!res); + +} + +#[test] +fn test_groth16() { + let mut rng = &mut ark_std::test_rng(); + let mimc = MiMC::::new( + 1, + Fr::zero(), + round_keys_contants_to_vec(&MIMC_7_91_BLS12_381_ROUND_KEYS), + ); + + let a = Fr::from(20); + let b = Fr::from(200); + let c = Fr::from(10); + + let d = c * as TwoToOneCRH>::evaluate( + &mimc, + &to_bytes!(a).unwrap(), + &to_bytes!(b).unwrap(), + ) + .unwrap(); + + // instantce g2 + let mut bytes = Vec::::new(); + d.serialize(&mut bytes).unwrap(); + + let mut buf = [0u8; 32]; + (&mut buf[0..32]).copy_from_slice(&bytes[..]); + + let scalar = Scalar::from_bytes(&buf).unwrap(); + let point = G2Affine::generator() * scalar; + println!("point: {:?}", point); + + + let test: HashProof = HashProof { + pw_point: Some(a), + nonce_point: Some(b), + random_r: Some(c), }; + + let (pk, vk) = Groth16::::setup(test.clone(), &mut rng).unwrap(); + + let pvk = prepare_verifying_key::(&vk); + + let proof = Groth16::::prove( + &pk, + HashProof { + pw_point: Some(a), + nonce_point: Some(b), + random_r: Some(c), + }, + &mut rng, + ) + .unwrap(); + + let start = Instant::now(); + for _i in 0..100{ + let proof = Groth16::::prove( + &pk, + HashProof { + pw_point: Some(a), + nonce_point: Some(b), + random_r: Some(c), + }, + &mut rng, + ) + .unwrap(); + } + + println!("{:.2?} Groth16::::prove(", start.elapsed()/100); + + let res = Groth16::::verify_with_processed_vk(&pvk, &[d], &proof); + + // let start = Instant::now(); + // for _i in 0..100{ + // let res = Groth16::::verify_with_processed_vk(&pvk, &[a,b,Fr::from(1)], &proof); + // } + + println!("{:.2?} verify_with_processed_vk", start.elapsed()/100); + + println!("res: {:?}", res.unwrap()); + + //serialization test + + let mut compressed_proof = Vec::new(); + proof.serialize(&mut compressed_proof).unwrap(); + let proof2 = Proof::::deserialize(&compressed_proof[..]).unwrap(); + assert_eq!(proof, proof2); + + let mut compressed_pvk = Vec::new(); + vk.serialize(&mut compressed_pvk).unwrap(); + let vk2 = VerifyingKey::::deserialize(&compressed_pvk[..]).unwrap(); + assert_eq!(vk, vk2); + let pk2 = prepare_verifying_key(&vk2); + assert_eq!(pvk, pk2); + + +} + +#[test] +fn test_constraint() -> Result<(), ark_relations::r1cs::SynthesisError> { + let rng = &mut ark_std::test_rng(); + let cs = ConstraintSystem::::new_ref(); + let mimc = MiMC::::new( + 1, + Fr::zero(), + round_keys_contants_to_vec(&MIMC_7_91_BLS12_381_ROUND_KEYS), + ); + + let x_l = Fr::from(20); + let x_r = Fr::from(200); + let hashed = as TwoToOneCRH>::evaluate( + &mimc, + &to_bytes!(x_l).unwrap(), + &to_bytes!(x_r).unwrap(), + ) + .unwrap(); + + let x_l_var = FpVar::new_witness(cs.clone(), || Ok(x_l))?; + let x_r_var = FpVar::new_witness(cs.clone(), || Ok(x_r))?; + let k_var = FpVar::new_input(cs.clone(), || Ok(mimc.k))?; + + let round_keys = Vec::>::new_constant(cs.clone(), mimc.round_keys)?; + let mimc_var = MiMCVar::<_, _>::new(1, k_var, round_keys); + let hashed_var = as TwoToOneCRHGadget< + MiMCFeistelCRH<_, _>, + _, + >>::evaluate(&mimc_var, &x_l_var.to_bytes()?, &x_r_var.to_bytes()?) + .unwrap(); + + assert!(FpVar::constant(hashed).is_eq(&hashed_var)?.value()?); + + let additional_input = FpVar::new_input(cs.clone(), || Ok(Fr::from(10)))?; + + // make input additional_input * hashed + + let hashed_var2 = hashed_var.clone() * additional_input; + + println!("hashed: {:?}", hashed_var2.value()?); + + cs.is_satisfied()?; + + println!("constraints: {}", cs.clone().num_constraints()); + println!("inputs: {}", cs.clone().num_instance_variables()); + println!("aux: {}", cs.clone().num_witness_variables()); + + // try building a circurit for the nizk + + Ok(()) +}