diff --git a/.github/workflows/benchmark-self-hosted.yml b/.github/workflows/benchmark-self-hosted.yml index ff89aef..50873f2 100644 --- a/.github/workflows/benchmark-self-hosted.yml +++ b/.github/workflows/benchmark-self-hosted.yml @@ -6,7 +6,7 @@ on: config_path: description: "Path to Configuration File" required: true - default: "secpar_0_height_2.params.toml" + default: "secpar_20_height_1_p_6.params.toml" data_id: description: "Data ID (e.g. 53)" @@ -54,7 +54,7 @@ jobs: uses: actions/checkout@v4 with: repository: MachinaIO/openfhe-development - ref: feat/improve_determinant + ref: main path: openfhe - name: Build & install OpenFHE @@ -62,7 +62,7 @@ jobs: run: | cd openfhe mkdir -p build && cd build - cmake .. + cmake .. -DWITH_OPENMP=OFF make -j"$(nproc)" sudo make install echo "/usr/local/lib" | sudo tee /etc/ld.so.conf.d/openfhe.conf @@ -81,19 +81,20 @@ jobs: env: LD_LIBRARY_PATH: /usr/local/lib RUST_LOG: info + RUST_BACKTRACE: 1 run: | mkdir -p logs - # Run abe for offline computation with hardcoded config path as requested - ( - abe bench-run-offline \ + LOGFILE=logs/data_${{ github.event.inputs.data_id }}.log + + { + abe bench-run-offline \ + --config abe/run_configs/${{ github.event.inputs.config_path }} \ + --data-dir data_${{ github.event.inputs.data_id }} && + abe bench-run-online \ --config abe/run_configs/${{ github.event.inputs.config_path }} \ - --data-dir data_${{ github.event.inputs.data_id }} \ - 2>&1 | tee logs/data_${{ github.event.inputs.data_id }}.log - ) & - pid=$! - echo "Benchmark PID: $pid" - wait $pid + --data-dir data_${{ github.event.inputs.data_id }} + } 2>&1 | tee -a "$LOGFILE" - name: Install uv uses: astral-sh/setup-uv@v5 diff --git a/Cargo.lock b/Cargo.lock index b84c811..f1a4867 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,6 +13,7 @@ dependencies = [ "keccak-asm", "mxx", "num-bigint", + "rand 0.9.2", "serde", "tokio", "toml", @@ -20,26 +21,11 @@ dependencies = [ "tracing-subscriber", ] -[[package]] -name = "addr2line" -version = "0.25.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b5d307320b3181d6d7954e663bd7c774a838b8220fe0593c86d9fb09f498b4b" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler2" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" - [[package]] name = "aho-corasick" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" dependencies = [ "memchr", ] @@ -85,22 +71,22 @@ dependencies = [ [[package]] name = "anstyle-query" -version = "1.1.4" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e231f6134f61b71076a3eab506c379d4f36122f2af15a9ff04415ea4c3339e2" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" dependencies = [ - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] name = "anstyle-wincon" -version = "3.0.10" +version = "3.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -129,26 +115,11 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" -[[package]] -name = "backtrace" -version = "0.3.76" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb531853791a215d7c62a30daf0dde835f381ab5de4589cfe7c649d2cbe92bd6" -dependencies = [ - "addr2line", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", - "windows-link", -] - [[package]] name = "bigdecimal" -version = "0.4.8" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a22f228ab7a1b23027ccc6c350b72868017af7ea8356fbdf19f8d991c690013" +checksum = "4d6867f1565b3aad85681f1015055b087fcfd840d6aeee6eee7f2da317603695" dependencies = [ "autocfg", "libm", @@ -179,9 +150,9 @@ dependencies = [ [[package]] name = "bitflags" -version = "2.9.4" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394" +checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" [[package]] name = "bitvec" @@ -206,15 +177,15 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.19.0" +version = "3.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" +checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510" [[package]] name = "cc" -version = "1.2.41" +version = "1.2.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac9fe6cdbb24b6ade63616c0a0688e45bb56732262c158df3c0c4bea4ca47cb7" +checksum = "cd4932aefd12402b36c60956a4fe0035421f544799057659ff86f923657aada3" dependencies = [ "find-msvc-tools", "shlex", @@ -222,9 +193,9 @@ dependencies = [ [[package]] name = "cfg-if" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] name = "chrono" @@ -241,9 +212,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.48" +version = "4.5.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2134bb3ea021b78629caa971416385309e0131b351b25e01dc16fb54e1b5fae" +checksum = "c6e6ff9dcd79cff5cd969a17a545d79e84ab086e444102a591e288a8aa3ce394" dependencies = [ "clap_builder", "clap_derive", @@ -251,9 +222,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.48" +version = "4.5.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2ba64afa3c0a6df7fa517765e31314e983f51dda798ffba27b988194fb65dc9" +checksum = "fa42cf4d2b7a41bc8f663a7cab4031ebafa1bf3875705bfaf8466dc60ab52c00" dependencies = [ "anstream", "anstyle", @@ -263,9 +234,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.47" +version = "4.5.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbfd7eae0b0f1a6e63d4b13c9c478de77c2eb546fba158ad50b4203dc24b9f9c" +checksum = "2a0b5487afeab2deb2ff4e03a807ad1a03ac532ff5a2cee5d86884440c7f7671" dependencies = [ "heck", "proc-macro2", @@ -275,15 +246,15 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.5" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" +checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" [[package]] name = "codespan-reporting" -version = "0.12.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe6d2e5af09e8c8ad56c969f2157a3d4238cebc7c55f0a517728c38f7b200f81" +checksum = "af491d569909a7e4dee0ad7db7f5341fef5c614d5b8ec8cf765732aba3cff681" dependencies = [ "serde", "termcolor", @@ -329,9 +300,9 @@ checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" [[package]] name = "crypto-common" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" dependencies = [ "generic-array", "typenum", @@ -339,9 +310,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.186" +version = "1.0.192" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e9c4fe7f2f5dc5c62871a1b43992d197da6fa1394656a94276ac2894a90a6fe" +checksum = "bbda285ba6e5866529faf76352bdf73801d9b44a6308d7cd58ca2379f378e994" dependencies = [ "cc", "cxx-build", @@ -354,9 +325,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.186" +version = "1.0.192" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5cf2909d37d80633ddd208676fc27c2608a7f035fff69c882421168038b26dd" +checksum = "af9efde466c5d532d57efd92f861da3bdb7f61e369128ce8b4c3fe0c9de4fa4d" dependencies = [ "cc", "codespan-reporting", @@ -369,9 +340,9 @@ dependencies = [ [[package]] name = "cxxbridge-cmd" -version = "1.0.186" +version = "1.0.192" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "077f5ee3d3bfd8d27f83208fdaa96ddd50af7f096c77077cc4b94da10bfacefd" +checksum = "3efb93799095bccd4f763ca07997dc39a69e5e61ab52d2c407d4988d21ce144d" dependencies = [ "clap", "codespan-reporting", @@ -383,20 +354,19 @@ dependencies = [ [[package]] name = "cxxbridge-flags" -version = "1.0.186" +version = "1.0.192" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0108748615125b9f2e915dfafdffcbdabbca9b15102834f6d7e9a768f2f2864" +checksum = "3092010228026e143b32a4463ed9fa8f86dca266af4bf5f3b2a26e113dbe4e45" [[package]] name = "cxxbridge-macro" -version = "1.0.186" +version = "1.0.192" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6e896681ef9b8dc462cfa6961d61909704bde0984b30bcb4082fe102b478890" +checksum = "31d72ebfcd351ae404fb00ff378dfc9571827a00722c9e735c9181aec320ba0a" dependencies = [ "indexmap", "proc-macro2", "quote", - "rustversion", "syn", ] @@ -432,9 +402,9 @@ checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" [[package]] name = "env_filter" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "186e05a59d4c50738528153b83b0b0194d3a29507dfec16eccd4b342903397d0" +checksum = "1bf3c259d255ca70051b30e2e95b5446cdb8949ac4cd22c0d7fd634d89f568e2" dependencies = [ "log", "regex", @@ -477,9 +447,9 @@ checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" [[package]] name = "find-msvc-tools" -version = "0.1.4" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127" +checksum = "f449e6c6c08c865631d4890cfacf252b3d396c9bcc83adb6623cdb02a8336c41" [[package]] name = "foldhash" @@ -505,22 +475,16 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" dependencies = [ "cfg-if", "libc", "r-efi", - "wasi 0.14.7+wasi-0.2.4", + "wasip2", ] -[[package]] -name = "gimli" -version = "0.32.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e629b9b98ef3dd8afe6ca2bd0f89306cec16d43d907889945bc5d6687f2f13c7" - [[package]] name = "hashbrown" version = "0.14.5" @@ -529,9 +493,9 @@ checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" [[package]] name = "hashbrown" -version = "0.16.0" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" [[package]] name = "heck" @@ -565,30 +529,19 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.11.4" +version = "2.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b0f83760fb341a774ed326568e19f5a863af4a952def8c39f9ab92fd95b88e5" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" dependencies = [ "equivalent", - "hashbrown 0.16.0", -] - -[[package]] -name = "io-uring" -version = "0.7.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "046fa2d4d00aea763528b4950358d0ead425372445dc8ff86312b3c69ff7727b" -dependencies = [ - "bitflags", - "cfg-if", - "libc", + "hashbrown 0.16.1", ] [[package]] name = "is_terminal_polyfill" -version = "1.70.1" +version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" [[package]] name = "itertools" @@ -601,28 +554,28 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.15" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" +checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" [[package]] name = "jiff" -version = "0.2.15" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be1f93b8b1eb69c77f24bbb0afdf66f54b632ee39af40ca21c4365a1d7347e49" +checksum = "e67e8da4c49d6d9909fe03361f9b620f58898859f5c7aded68351e85e71ecf50" dependencies = [ "jiff-static", "log", "portable-atomic", "portable-atomic-util", - "serde", + "serde_core", ] [[package]] name = "jiff-static" -version = "0.2.15" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03343451ff899767262ec32146f6d559dd759fdadf42ff0e227c7c48f72594b4" +checksum = "e0c84ee7f197eca9a86c6fd6cb771e55eb991632f15f2bc3ca6ec838929e6e78" dependencies = [ "proc-macro2", "quote", @@ -631,9 +584,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.81" +version = "0.3.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec48937a97411dcb524a265206ccd4c90bb711fca92b2792c407f268825b9305" +checksum = "464a3709c7f55f1f721e5389aa6ea4e3bc6aba669353300af094b29ffbdde1d8" dependencies = [ "once_cell", "wasm-bindgen", @@ -657,9 +610,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.177" +version = "0.2.180" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" +checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" [[package]] name = "libm" @@ -693,9 +646,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.28" +version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" [[package]] name = "matchers" @@ -722,30 +675,10 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "miniz_oxide" -version = "0.8.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" -dependencies = [ - "adler2", -] - -[[package]] -name = "mio" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78bed444cc8a2160f01cbcf811ef18cac863ad68ae8ca62092e8db51d51c761c" -dependencies = [ - "libc", - "wasi 0.11.1+wasi-snapshot-preview1", - "windows-sys 0.59.0", -] - [[package]] name = "mxx" version = "0.1.0" -source = "git+https://github.com/MachinaIO/mxx.git#d81081fee29d1853e38f714ed725c545ebf45952" +source = "git+https://github.com/MachinaIO/mxx.git?branch=feat%2Fcommit_lookup_eval_simu#5bcb3866947a1563e4c6fac627ba18d56127fa46" dependencies = [ "bigdecimal", "bincode", @@ -808,15 +741,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "object" -version = "0.37.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff76201f031d8863c38aa7f905eca4f53abbfa15f609db4277d44cd8938f33fe" -dependencies = [ - "memchr", -] - [[package]] name = "once_cell" version = "1.21.3" @@ -825,14 +749,14 @@ checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" [[package]] name = "once_cell_polyfill" -version = "1.70.1" +version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" [[package]] name = "openfhe" version = "0.3.2" -source = "git+https://github.com/MachinaIO/openfhe-rs.git#1845c23031b7c95040456003aafc892c3228741b" +source = "git+https://github.com/MachinaIO/openfhe-rs.git#aaea3779c29559153b7018c05b9e9153e54e7c0d" dependencies = [ "cxx", "cxx-build", @@ -861,9 +785,9 @@ checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" [[package]] name = "portable-atomic" -version = "1.11.1" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483" +checksum = "f89776e4d69bb58bc6993e99ffa1d11f228b839984854c7daeb5d37f87cbe950" [[package]] name = "portable-atomic-util" @@ -885,18 +809,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.101" +version = "1.0.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" +checksum = "535d180e0ecab6268a3e718bb9fd44db66bbbc256257165fc699dadf70d16fe7" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.41" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1" +checksum = "dc74d9a594b72ae6656596548f56f667211f8a97b3d4c3d467150794690dc40a" dependencies = [ "proc-macro2", ] @@ -988,9 +912,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.12.1" +version = "1.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a52d8d02cacdb176ef4678de6c052efb4b3da14b78e4db683a4252762be5433" +checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" dependencies = [ "aho-corasick", "memchr", @@ -1000,9 +924,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.12" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "722166aa0d7438abbaa4d5cc2c649dac844e8c56d82fb3d33e9c34b5cd268fc6" +checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" dependencies = [ "aho-corasick", "memchr", @@ -1011,21 +935,15 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.7" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3160422bbd54dd5ecfdca71e5fd59b7b8fe2b1697ab2baf64f6d05dcc66d298" - -[[package]] -name = "rustc-demangle" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56f7d92ca342cea22a06f2121d944b4fd82af56988c270852495420f961d4ace" +checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" [[package]] name = "rustix" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e" +checksum = "146c9e247ccc180c1f61615433868c99f3de3ae256a30a43b49f67c2d9171f34" dependencies = [ "bitflags", "errno", @@ -1040,12 +958,6 @@ version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" -[[package]] -name = "ryu" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" - [[package]] name = "scopeguard" version = "1.2.0" @@ -1090,22 +1002,22 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.145" +version = "1.0.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" dependencies = [ "itoa", "memchr", - "ryu", "serde", "serde_core", + "zmij", ] [[package]] name = "serde_spanned" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e24345aa0fe688594e73770a5f6d1b216508b4f93484c0026d521acd30134392" +checksum = "f8bbf91e5a4d6315eee45e704372590b30e260ee83af6639d64557f51b067776" dependencies = [ "serde_core", ] @@ -1135,12 +1047,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" -[[package]] -name = "slab" -version = "0.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" - [[package]] name = "smallvec" version = "1.15.1" @@ -1155,9 +1061,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.106" +version = "2.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" +checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" dependencies = [ "proc-macro2", "quote", @@ -1172,9 +1078,9 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "tempfile" -version = "3.23.0" +version = "3.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d31c77bdf42a745371d260a26ca7163f1e0924b64afa0b688e61b5a9fa02f16" +checksum = "655da9c7eb6305c55742045d5a8d2037996d61d8de95806335c7c86ce0f82e9c" dependencies = [ "fastrand", "getrandom", @@ -1243,24 +1149,19 @@ dependencies = [ [[package]] name = "tokio" -version = "1.47.1" +version = "1.49.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89e49afdadebb872d3145a5638b59eb0691ea23e46ca484037cfab3b76b95038" +checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86" dependencies = [ - "backtrace", - "io-uring", - "libc", - "mio", "pin-project-lite", - "slab", "tokio-macros", ] [[package]] name = "tokio-macros" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" +checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5" dependencies = [ "proc-macro2", "quote", @@ -1269,9 +1170,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.9.8" +version = "0.9.11+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0dc8b1fb61449e27716ec0e1bdf0f6b8f3e8f6b05391e8497b8b6d7804ea6d8" +checksum = "f3afc9a848309fe1aaffaed6e1546a7a14de1f935dc9d89d32afd9a44bab7c46" dependencies = [ "indexmap", "serde_core", @@ -1284,33 +1185,33 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.7.3" +version = "0.7.5+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2cdb639ebbc97961c51720f858597f7f24c4fc295327923af55b74c3c724533" +checksum = "92e1cfed4a3038bc5a127e35a2d360f145e1f4b971b551a2ba5fd7aedf7e1347" dependencies = [ "serde_core", ] [[package]] name = "toml_parser" -version = "1.0.4" +version = "1.0.6+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0cbe268d35bdb4bb5a56a2de88d0ad0eb70af5384a99d648cd4b3d04039800e" +checksum = "a3198b4b0a8e11f09dd03e133c0280504d0801269e9afa46362ffde1cbeebf44" dependencies = [ "winnow", ] [[package]] name = "toml_writer" -version = "1.0.4" +version = "1.0.6+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df8b2b54733674ad286d16267dcfc7a71ed5c776e4ac7aa3c3e2561f7c637bf2" +checksum = "ab16f14aed21ee8bfd8ec22513f7287cd4a91aa92e44edfe2c17ddd004e92607" [[package]] name = "tracing" -version = "0.1.41" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" dependencies = [ "pin-project-lite", "tracing-attributes", @@ -1319,9 +1220,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.30" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" dependencies = [ "proc-macro2", "quote", @@ -1330,9 +1231,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.34" +version = "0.1.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9d12581f227e93f094d3af2ae690a574abb8a2b9b7a96e7cfe9647b2b617678" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" dependencies = [ "once_cell", "valuable", @@ -1351,9 +1252,9 @@ dependencies = [ [[package]] name = "tracing-subscriber" -version = "0.3.20" +version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2054a14f5307d601f88daf0553e1cbf472acc4f2c51afab632431cdcd72124d5" +checksum = "2f30143827ddab0d256fd843b7a66d164e9f271cfa0dde49142c5ca0ca291f1e" dependencies = [ "matchers", "nu-ansi-term", @@ -1375,9 +1276,9 @@ checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" [[package]] name = "unicode-ident" -version = "1.0.19" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" [[package]] name = "unicode-width" @@ -1415,21 +1316,6 @@ version = "0.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "051eb1abcf10076295e815102942cc58f9d5e3b4560e46e53c21e8ff6f3af7b1" -[[package]] -name = "wasi" -version = "0.11.1+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" - -[[package]] -name = "wasi" -version = "0.14.7+wasi-0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "883478de20367e224c0090af9cf5f9fa85bed63a95c1abf3afc5c083ebc06e8c" -dependencies = [ - "wasip2", -] - [[package]] name = "wasip2" version = "1.0.1+wasi-0.2.4" @@ -1441,9 +1327,9 @@ dependencies = [ [[package]] name = "wasm-bindgen" -version = "0.2.104" +version = "0.2.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1da10c01ae9f1ae40cbfac0bac3b1e724b320abfcf52229f80b547c0d250e2d" +checksum = "0d759f433fa64a2d763d1340820e46e111a7a5ab75f993d1852d70b03dbb80fd" dependencies = [ "cfg-if", "once_cell", @@ -1452,25 +1338,11 @@ dependencies = [ "wasm-bindgen-shared", ] -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.104" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "671c9a5a66f49d8a47345ab942e2cb93c7d1d0339065d4f8139c486121b43b19" -dependencies = [ - "bumpalo", - "log", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - [[package]] name = "wasm-bindgen-macro" -version = "0.2.104" +version = "0.2.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ca60477e4c59f5f2986c50191cd972e3a50d8a95603bc9434501cf156a9a119" +checksum = "48cb0d2638f8baedbc542ed444afc0644a29166f1595371af4fecf8ce1e7eeb3" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1478,22 +1350,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.104" +version = "0.2.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f07d2f20d4da7b26400c9f4a0511e6e0345b040694e8a75bd41d578fa4421d7" +checksum = "cefb59d5cd5f92d9dcf80e4683949f15ca4b511f4ac0a6e14d4e1ac60c6ecd40" dependencies = [ + "bumpalo", "proc-macro2", "quote", "syn", - "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.104" +version = "0.2.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bad67dc8b2a1a6e5448428adec4c3e84c43e561d8c9ee8a9e5aabeb193ec41d1" +checksum = "cbc538057e648b67f72a982e708d485b2efa771e1ac05fec311f9f63e5800db4" dependencies = [ "unicode-ident", ] @@ -1572,25 +1444,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.6", -] - -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - -[[package]] -name = "windows-sys" -version = "0.60.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" -dependencies = [ - "windows-targets 0.53.5", + "windows-targets", ] [[package]] @@ -1608,31 +1462,14 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.6", - "windows_aarch64_msvc 0.52.6", - "windows_i686_gnu 0.52.6", - "windows_i686_gnullvm 0.52.6", - "windows_i686_msvc 0.52.6", - "windows_x86_64_gnu 0.52.6", - "windows_x86_64_gnullvm 0.52.6", - "windows_x86_64_msvc 0.52.6", -] - -[[package]] -name = "windows-targets" -version = "0.53.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" -dependencies = [ - "windows-link", - "windows_aarch64_gnullvm 0.53.1", - "windows_aarch64_msvc 0.53.1", - "windows_i686_gnu 0.53.1", - "windows_i686_gnullvm 0.53.1", - "windows_i686_msvc 0.53.1", - "windows_x86_64_gnu 0.53.1", - "windows_x86_64_gnullvm 0.53.1", - "windows_x86_64_msvc 0.53.1", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] [[package]] @@ -1641,101 +1478,53 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" - [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" -[[package]] -name = "windows_aarch64_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" - [[package]] name = "windows_i686_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" -[[package]] -name = "windows_i686_gnu" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" - [[package]] name = "windows_i686_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" -[[package]] -name = "windows_i686_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" - [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" -[[package]] -name = "windows_i686_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" - [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" -[[package]] -name = "windows_x86_64_gnu" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" - [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" - [[package]] name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" -[[package]] -name = "windows_x86_64_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" - [[package]] name = "winnow" -version = "0.7.13" +version = "0.7.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21a0236b59786fed61e2a80582dd500fe61f18b5dca67a4a067d0bc9039339cf" +checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829" [[package]] name = "wit-bindgen" @@ -1754,20 +1543,26 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.27" +version = "0.8.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c" +checksum = "668f5168d10b9ee831de31933dc111a459c97ec93225beb307aed970d1372dfd" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.27" +version = "0.8.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831" +checksum = "2c7962b26b0a8685668b671ee4b54d007a67d4eaf05fda79ac0ecf41e32270f1" dependencies = [ "proc-macro2", "quote", "syn", ] + +[[package]] +name = "zmij" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fc5a66a20078bf1251bde995aa2fdcc4b800c70b5d92dd2c62abc5c60f679f8" diff --git a/Cargo.toml b/Cargo.toml index acb3e7c..33d5a4e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ version = "0.1.0" edition = "2024" [dependencies] -mxx = { git = "https://github.com/MachinaIO/mxx.git" } +mxx = { git = "https://github.com/MachinaIO/mxx.git", branch = "feat/commit_lookup_eval_simu" } rand = { version = "0.9.0", features = ["std_rng"] } num-bigint = { version = "0.4", features = ["serde"] } thiserror = "2.0.16" @@ -16,6 +16,7 @@ bigdecimal = { version = "0.4" } rayon = "1.10" log = "0.4" + [profile.dev] debug = "line-tables-only" split-debuginfo = "unpacked" diff --git a/abe/Cargo.toml b/abe/Cargo.toml index 6e91046..8135e3e 100644 --- a/abe/Cargo.toml +++ b/abe/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2024" [dependencies] -mxx = { git = "https://github.com/MachinaIO/mxx.git" } +mxx = { git = "https://github.com/MachinaIO/mxx.git", branch = "feat/commit_lookup_eval_simu" } arithmetic-abe = { path = "../" } anyhow = "1.0" clap = { version = "4.5", features = ["derive"] } @@ -16,3 +16,4 @@ serde = { version = "1.0", features = ["derive"] } toml = "0.9.5" tokio = { version = "1", features = ["fs", "rt-multi-thread", "macros"] } chrono = { version = "0.4", features = ["clock"] } +rand = { version = "0.9.0", features = ["std_rng"] } diff --git a/abe/run_configs/secpar_0_height_1_p_6.params.toml b/abe/run_configs/secpar_0_height_1_p_6.params.toml new file mode 100644 index 0000000..392b61f --- /dev/null +++ b/abe/run_configs/secpar_0_height_1_p_6.params.toml @@ -0,0 +1,13 @@ +config_id = "secpar_0_height_1_p_6.params.toml" +target_secpar = 0 +crt_depth = 11 +crt_bits = 24 +ring_dimension = 16 +knapsack_size = 34 +e_b_sigma = 4.0 +trapdoor_sigma = 4.578 +base_bits = 8 +p_moduli_bits = 6 +scale = 256 +arith_input_size = 2 +arith_height = 1 diff --git a/abe/run_configs/secpar_0_height_2.params.toml b/abe/run_configs/secpar_0_height_2.params.toml deleted file mode 100644 index e80ec59..0000000 --- a/abe/run_configs/secpar_0_height_2.params.toml +++ /dev/null @@ -1,12 +0,0 @@ -config_id = "secpar_0_height_2.params.toml" -target_secpar = 0 -crt_depth = 2 -crt_bits = 10 -ring_dimension = 4 -num_eval_slots = 1 -e_b_sigma = 0.0 -trapdoor_sigma = 4.578 -base_bits = 7 -limb_bit_size = 2 -arith_input_size = 4 -arith_height = 2 diff --git a/abe/run_configs/secpar_120_height_1_p_6.params.toml b/abe/run_configs/secpar_120_height_1_p_6.params.toml new file mode 100644 index 0000000..a7408bb --- /dev/null +++ b/abe/run_configs/secpar_120_height_1_p_6.params.toml @@ -0,0 +1,13 @@ +config_id = "secpar_120_height_1_p_6.params.toml" +target_secpar = 120 +crt_depth = 15 +crt_bits = 24 +ring_dimension = 16384 +knapsack_size = 31 +e_b_sigma = 4.0 +trapdoor_sigma = 4.578 +base_bits = 12 +p_moduli_bits = 6 +scale = 256 +arith_input_size = 2 +arith_height = 1 diff --git a/abe/sim_configs/secpar_0_height_1_p_6.params.toml b/abe/sim_configs/secpar_0_height_1_p_6.params.toml new file mode 100644 index 0000000..a30637b --- /dev/null +++ b/abe/sim_configs/secpar_0_height_1_p_6.params.toml @@ -0,0 +1,11 @@ +target_secpar = 0 +crt_bits = 24 +crt_depth_min = 11 +crt_depth_max = 15 +base_bits_min = 8 +base_bits_max = 8 +log_dim_min = 4 +log_dim_max = 4 +p_moduli_bits = 6 +scale_bits = 8 +height = 1 diff --git a/abe/sim_configs/secpar_120_height_1_limb_1.params.toml b/abe/sim_configs/secpar_120_height_1_limb_1.params.toml deleted file mode 100644 index 6aba0b5..0000000 --- a/abe/sim_configs/secpar_120_height_1_limb_1.params.toml +++ /dev/null @@ -1,11 +0,0 @@ -target_secpar = 120 -crt_bits = 32 -crt_depth_min = 1 -crt_depth_max = 1 -base_bits_min = 17 -base_bits_max = 17 -log_dim_min = 15 -log_dim_max = 15 -num_eval_slots = 1 -limb_bit_size = 1 -height = 1 diff --git a/abe/sim_configs/secpar_120_height_1_limb_10.params.toml b/abe/sim_configs/secpar_120_height_1_limb_10.params.toml deleted file mode 100644 index 2e4fbfe..0000000 --- a/abe/sim_configs/secpar_120_height_1_limb_10.params.toml +++ /dev/null @@ -1,11 +0,0 @@ -target_secpar = 120 -crt_bits = 32 -crt_depth_min = 1 -crt_depth_max = 1 -base_bits_min = 17 -base_bits_max = 17 -log_dim_min = 15 -log_dim_max = 15 -num_eval_slots = 1 -limb_bit_size = 10 -height = 1 diff --git a/abe/sim_configs/secpar_120_height_1_limb_11.params.toml b/abe/sim_configs/secpar_120_height_1_limb_11.params.toml deleted file mode 100644 index 1fa5c6d..0000000 --- a/abe/sim_configs/secpar_120_height_1_limb_11.params.toml +++ /dev/null @@ -1,11 +0,0 @@ -target_secpar = 120 -crt_bits = 32 -crt_depth_min = 1 -crt_depth_max = 1 -base_bits_min = 17 -base_bits_max = 17 -log_dim_min = 15 -log_dim_max = 15 -num_eval_slots = 1 -limb_bit_size = 11 -height = 1 diff --git a/abe/sim_configs/secpar_120_height_1_limb_12.params.toml b/abe/sim_configs/secpar_120_height_1_limb_12.params.toml deleted file mode 100644 index 113cb81..0000000 --- a/abe/sim_configs/secpar_120_height_1_limb_12.params.toml +++ /dev/null @@ -1,11 +0,0 @@ -target_secpar = 120 -crt_bits = 32 -crt_depth_min = 1 -crt_depth_max = 1 -base_bits_min = 17 -base_bits_max = 17 -log_dim_min = 15 -log_dim_max = 15 -num_eval_slots = 1 -limb_bit_size = 12 -height = 1 diff --git a/abe/sim_configs/secpar_120_height_1_limb_13.params.toml b/abe/sim_configs/secpar_120_height_1_limb_13.params.toml deleted file mode 100644 index c3dcf4a..0000000 --- a/abe/sim_configs/secpar_120_height_1_limb_13.params.toml +++ /dev/null @@ -1,11 +0,0 @@ -target_secpar = 120 -crt_bits = 32 -crt_depth_min = 1 -crt_depth_max = 1 -base_bits_min = 17 -base_bits_max = 17 -log_dim_min = 15 -log_dim_max = 15 -num_eval_slots = 1 -limb_bit_size = 13 -height = 1 diff --git a/abe/sim_configs/secpar_120_height_1_limb_14.params.toml b/abe/sim_configs/secpar_120_height_1_limb_14.params.toml deleted file mode 100644 index fc55843..0000000 --- a/abe/sim_configs/secpar_120_height_1_limb_14.params.toml +++ /dev/null @@ -1,11 +0,0 @@ -target_secpar = 120 -crt_bits = 32 -crt_depth_min = 1 -crt_depth_max = 1 -base_bits_min = 17 -base_bits_max = 17 -log_dim_min = 15 -log_dim_max = 15 -num_eval_slots = 1 -limb_bit_size = 14 -height = 1 diff --git a/abe/sim_configs/secpar_120_height_1_limb_15.params.toml b/abe/sim_configs/secpar_120_height_1_limb_15.params.toml deleted file mode 100644 index 7d6f991..0000000 --- a/abe/sim_configs/secpar_120_height_1_limb_15.params.toml +++ /dev/null @@ -1,11 +0,0 @@ -target_secpar = 120 -crt_bits = 32 -crt_depth_min = 1 -crt_depth_max = 1 -base_bits_min = 17 -base_bits_max = 17 -log_dim_min = 15 -log_dim_max = 15 -num_eval_slots = 1 -limb_bit_size = 15 -height = 1 diff --git a/abe/sim_configs/secpar_120_height_1_limb_16.params.toml b/abe/sim_configs/secpar_120_height_1_limb_16.params.toml deleted file mode 100644 index 1808d85..0000000 --- a/abe/sim_configs/secpar_120_height_1_limb_16.params.toml +++ /dev/null @@ -1,11 +0,0 @@ -target_secpar = 120 -crt_bits = 32 -crt_depth_min = 1 -crt_depth_max = 1 -base_bits_min = 17 -base_bits_max = 17 -log_dim_min = 15 -log_dim_max = 15 -num_eval_slots = 1 -limb_bit_size = 16 -height = 1 diff --git a/abe/sim_configs/secpar_120_height_1_limb_2.params.toml b/abe/sim_configs/secpar_120_height_1_limb_2.params.toml deleted file mode 100644 index 5bc2711..0000000 --- a/abe/sim_configs/secpar_120_height_1_limb_2.params.toml +++ /dev/null @@ -1,11 +0,0 @@ -target_secpar = 120 -crt_bits = 32 -crt_depth_min = 1 -crt_depth_max = 1 -base_bits_min = 17 -base_bits_max = 17 -log_dim_min = 15 -log_dim_max = 15 -num_eval_slots = 1 -limb_bit_size = 2 -height = 1 diff --git a/abe/sim_configs/secpar_120_height_1_limb_3.params.toml b/abe/sim_configs/secpar_120_height_1_limb_3.params.toml deleted file mode 100644 index 6a1b62b..0000000 --- a/abe/sim_configs/secpar_120_height_1_limb_3.params.toml +++ /dev/null @@ -1,11 +0,0 @@ -target_secpar = 120 -crt_bits = 32 -crt_depth_min = 1 -crt_depth_max = 1 -base_bits_min = 17 -base_bits_max = 17 -log_dim_min = 15 -log_dim_max = 15 -num_eval_slots = 1 -limb_bit_size = 3 -height = 1 diff --git a/abe/sim_configs/secpar_120_height_1_limb_4.params.toml b/abe/sim_configs/secpar_120_height_1_limb_4.params.toml deleted file mode 100644 index 3b61d4f..0000000 --- a/abe/sim_configs/secpar_120_height_1_limb_4.params.toml +++ /dev/null @@ -1,11 +0,0 @@ -target_secpar = 120 -crt_bits = 32 -crt_depth_min = 1 -crt_depth_max = 1 -base_bits_min = 17 -base_bits_max = 17 -log_dim_min = 15 -log_dim_max = 15 -num_eval_slots = 1 -limb_bit_size = 4 -height = 1 diff --git a/abe/sim_configs/secpar_120_height_1_limb_5.params.toml b/abe/sim_configs/secpar_120_height_1_limb_5.params.toml deleted file mode 100644 index 97de0d5..0000000 --- a/abe/sim_configs/secpar_120_height_1_limb_5.params.toml +++ /dev/null @@ -1,11 +0,0 @@ -target_secpar = 120 -crt_bits = 32 -crt_depth_min = 1 -crt_depth_max = 1 -base_bits_min = 17 -base_bits_max = 17 -log_dim_min = 15 -log_dim_max = 15 -num_eval_slots = 1 -limb_bit_size = 5 -height = 1 diff --git a/abe/sim_configs/secpar_120_height_1_limb_6.params.toml b/abe/sim_configs/secpar_120_height_1_limb_6.params.toml deleted file mode 100644 index ab94fd9..0000000 --- a/abe/sim_configs/secpar_120_height_1_limb_6.params.toml +++ /dev/null @@ -1,11 +0,0 @@ -target_secpar = 120 -crt_bits = 32 -crt_depth_min = 1 -crt_depth_max = 1 -base_bits_min = 17 -base_bits_max = 17 -log_dim_min = 15 -log_dim_max = 15 -num_eval_slots = 1 -limb_bit_size = 6 -height = 1 diff --git a/abe/sim_configs/secpar_120_height_1_limb_7.params.toml b/abe/sim_configs/secpar_120_height_1_limb_7.params.toml deleted file mode 100644 index 6122203..0000000 --- a/abe/sim_configs/secpar_120_height_1_limb_7.params.toml +++ /dev/null @@ -1,11 +0,0 @@ -target_secpar = 120 -crt_bits = 32 -crt_depth_min = 1 -crt_depth_max = 1 -base_bits_min = 17 -base_bits_max = 17 -log_dim_min = 15 -log_dim_max = 15 -num_eval_slots = 1 -limb_bit_size = 7 -height = 1 diff --git a/abe/sim_configs/secpar_120_height_1_limb_8.params.toml b/abe/sim_configs/secpar_120_height_1_limb_8.params.toml deleted file mode 100644 index b59bc7f..0000000 --- a/abe/sim_configs/secpar_120_height_1_limb_8.params.toml +++ /dev/null @@ -1,11 +0,0 @@ -target_secpar = 120 -crt_bits = 32 -crt_depth_min = 1 -crt_depth_max = 1 -base_bits_min = 17 -base_bits_max = 17 -log_dim_min = 15 -log_dim_max = 15 -num_eval_slots = 1 -limb_bit_size = 8 -height = 1 diff --git a/abe/sim_configs/secpar_120_height_1_limb_9.params.toml b/abe/sim_configs/secpar_120_height_1_limb_9.params.toml deleted file mode 100644 index 5ba92e3..0000000 --- a/abe/sim_configs/secpar_120_height_1_limb_9.params.toml +++ /dev/null @@ -1,11 +0,0 @@ -target_secpar = 120 -crt_bits = 32 -crt_depth_min = 1 -crt_depth_max = 1 -base_bits_min = 17 -base_bits_max = 17 -log_dim_min = 15 -log_dim_max = 15 -num_eval_slots = 1 -limb_bit_size = 9 -height = 1 diff --git a/abe/sim_configs/secpar_120_height_1_p_6.params.toml b/abe/sim_configs/secpar_120_height_1_p_6.params.toml new file mode 100644 index 0000000..cad7c1a --- /dev/null +++ b/abe/sim_configs/secpar_120_height_1_p_6.params.toml @@ -0,0 +1,11 @@ +target_secpar = 120 +crt_bits = 24 +crt_depth_min = 10 +crt_depth_max = 30 +base_bits_min = 12 +base_bits_max = 12 +log_dim_min = 13 +log_dim_max = 16 +p_moduli_bits = 6 +scale_bits = 8 +height = 1 diff --git a/abe/src/config.rs b/abe/src/config.rs index ce163aa..f11f67b 100644 --- a/abe/src/config.rs +++ b/abe/src/config.rs @@ -11,14 +11,14 @@ pub struct RunConfig { pub crt_depth: u32, pub crt_bits: u32, pub ring_dimension: u32, - pub num_eval_slots: Option, pub knapsack_size: Option, pub e_b_sigma: f64, #[serde(default = "default_trapdoor_sigma")] pub trapdoor_sigma: Option, /// bit size of the base for the gadget vector and decomposition pub base_bits: u32, - pub limb_bit_size: usize, + pub p_moduli_bits: usize, + pub scale: u64, pub arith_input_size: usize, pub arith_height: u32, // #[serde( @@ -38,7 +38,7 @@ pub struct SimConfig { pub base_bits_max: u32, pub log_dim_min: u32, pub log_dim_max: u32, - pub num_eval_slots: Option, - pub limb_bit_size: usize, + pub p_moduli_bits: usize, + pub scale_bits: u32, pub height: usize, } diff --git a/abe/src/main.rs b/abe/src/main.rs index 9ae2f02..5bbe90a 100644 --- a/abe/src/main.rs +++ b/abe/src/main.rs @@ -5,26 +5,23 @@ use arithmetic_abe::{ abe::KeyPolicyABE, ciphertext::Ciphertext, keys::{FuncSK, MasterPK, MasterSK}, - simulator::bruteforce_params_for_bench_arith_circuit, + simulator::bruteforce_params_for_bench_nested_crt_circuit, }; use chrono::Local; use clap::{Parser, Subcommand}; use keccak_asm::Keccak256; use mxx::{ - arithmetic::circuit::ArithmeticCircuit, matrix::dcrt_poly::DCRTPolyMatrix, - poly::{ - PolyParams, - dcrt::{params::DCRTPolyParams, poly::DCRTPoly}, - }, + poly::{PolyParams, dcrt::params::DCRTPolyParams}, sampler::{ - PolyTrapdoorSampler, hash::DCRTPolyHashSampler, trapdoor::DCRTPolyTrapdoorSampler, + hash::DCRTPolyHashSampler, trapdoor::DCRTPolyTrapdoorSampler, uniform::DCRTPolyUniformSampler, }, - utils::{log_mem, timed_read, timed_read_async}, + utils::{gen_biguint_for_modulus, timed_read, timed_read_async}, }; use num_bigint::BigUint; use std::{env, fs, path::PathBuf, time::Duration}; +use tracing::info; use tracing_subscriber::{EnvFilter, fmt}; #[derive(Parser, Debug)] @@ -74,7 +71,7 @@ async fn main() -> Result<()> { match cli.command { Commands::BenchSim { config } => { - log_mem(format!("Loading simulator config: path={}", config.display())); + info!("Loading simulator config: path={}", config.display()); let config_prefix = config .file_name() .map(|os| os.to_string_lossy().into_owned()) @@ -87,7 +84,7 @@ async fn main() -> Result<()> { run_bench_sim(sim_config, config_prefix)?; } Commands::BenchRunOffline { config, data_dir } => { - log_mem(format!("Loading run config: path={}", config.display())); + info!("Loading run config: path={}", config.display()); let contents = fs::read_to_string(&config) .with_context(|| format!("failed to read run config from {}", config.display()))?; let run_config: RunConfig = toml::from_str(&contents) @@ -95,7 +92,7 @@ async fn main() -> Result<()> { run_bench_offline(run_config, data_dir).await?; } Commands::BenchRunOnline { config, data_dir } => { - log_mem(format!("Loading run config: path={}", config.display())); + info!("Loading run config: path={}", config.display()); let contents = fs::read_to_string(&config) .with_context(|| format!("failed to read run config from {}", config.display()))?; let run_config: RunConfig = toml::from_str(&contents) @@ -121,13 +118,13 @@ fn run_bench_sim(config: SimConfig, config_prefix: String) -> Result<()> { base_bits_max, log_dim_min, log_dim_max, - num_eval_slots, - limb_bit_size, + p_moduli_bits, + scale_bits, height, } = config; - log_mem(format!( - "Starting benchmark parameter search: target_secpar={}, crt_bits={}, crt_depth_range=({}-{}), base_bits_range=({}-{}), log_dim_range=({}-{}), num_eval_slots={:?}, limb_bit_size={}, height={}, config_prefix={}", + info!( + "Starting benchmark parameter search: target_secpar={}, crt_bits={}, crt_depth_range=({}-{}), base_bits_range=({}-{}), log_dim_range=({}-{}), p_moduli_bits={}, scale_bits = {}, height={}, config_prefix={}", target_secpar, crt_bits, crt_depth_min, @@ -136,20 +133,20 @@ fn run_bench_sim(config: SimConfig, config_prefix: String) -> Result<()> { base_bits_max, log_dim_min, log_dim_max, - num_eval_slots, - limb_bit_size, + p_moduli_bits, + scale_bits, height, config_prefix - )); + ); - let params = bruteforce_params_for_bench_arith_circuit( + let params = bruteforce_params_for_bench_nested_crt_circuit( target_secpar, crt_bits, (crt_depth_min, crt_depth_max), (base_bits_min, base_bits_max), (log_dim_min, log_dim_max), - config.num_eval_slots, - limb_bit_size, + p_moduli_bits, + scale_bits, height, ) .context("unable to find parameters for benchmark arithmetic circuit")?; @@ -163,10 +160,10 @@ fn run_bench_sim(config: SimConfig, config_prefix: String) -> Result<()> { .checked_shl(arith_height) .context("arith_height is too large for usize input size")?; - log_mem(format!( + info!( "Benchmark parameter search succeeded: crt_depth={}, base_bits={}, log_dim={}, e_b_sigma={}, knapsack_size={}, ring_dimension={}, arith_input_size={}", crt_depth, base_bits, log_dim, e_b_sigma, knapsack_size, ring_dimension, arith_input_size - )); + ); let config_id = format!("{}_{}", config_prefix, Local::now().format("%Y%m%d-%H%M%S")); let run_config = RunConfig { @@ -179,8 +176,8 @@ fn run_bench_sim(config: SimConfig, config_prefix: String) -> Result<()> { e_b_sigma, trapdoor_sigma: Some(4.578), base_bits, - num_eval_slots: config.num_eval_slots, - limb_bit_size, + p_moduli_bits, + scale: 1 << scale_bits, arith_input_size, arith_height, }; @@ -195,7 +192,7 @@ fn run_bench_sim(config: SimConfig, config_prefix: String) -> Result<()> { fs::write(&output_path, toml) .with_context(|| format!("failed to write config file to {}", output_path.display()))?; - log_mem(format!("Wrote benchmark config: path={}", output_path.display())); + info!("Wrote benchmark config: path={}", output_path.display()); Ok(()) } @@ -207,41 +204,30 @@ async fn run_bench_offline(config: RunConfig, data_dir: PathBuf) -> Result<()> { config.crt_bits as usize, config.base_bits, ); - let trapdoor_sampler = - DCRTPolyTrapdoorSampler::new(¶ms, config.trapdoor_sigma.expect("trapdoor sigma exist")); + let trapdoor_sigma = config.trapdoor_sigma.expect("trapdoor sigma exist"); let abe = KeyPolicyABE::< DCRTPolyMatrix, DCRTPolyHashSampler, DCRTPolyTrapdoorSampler, DCRTPolyUniformSampler, >::new( - config.limb_bit_size, + config.p_moduli_bits, + config.scale, ¶ms, - config.num_eval_slots, config.knapsack_size, config.e_b_sigma, - trapdoor_sampler, + trapdoor_sigma, ); let mut t_setup = Duration::ZERO; let mut t_keygen = Duration::ZERO; - let num_eval_slots = config.num_eval_slots.unwrap_or(params.ring_dimension() as usize); - log_mem("starting KeyPolicy ABE"); - log_mem("start building arithmetic circuit"); - let arith_circuit = ArithmeticCircuit::::benchmark_multiplication_tree( - ¶ms, - config.limb_bit_size, - num_eval_slots, - config.arith_height as usize, - false, - ); - log_mem("finished building arithmetic circuit"); + info!("starting KeyPolicy ABE"); // 1) setup - log_mem("starting setup"); + info!("starting setup"); let (mpk, msk): (MasterPK, MasterSK) = - timed_read("setup", || abe.setup(params.clone(), config.arith_input_size), &mut t_setup); - log_mem("finished setup"); + timed_read("setup", || abe.setup(¶ms, config.arith_input_size), &mut t_setup); + info!("finished setup"); let dir_path = if data_dir.exists() { data_dir @@ -250,19 +236,19 @@ async fn run_bench_offline(config: RunConfig, data_dir: PathBuf) -> Result<()> { data_dir }; // 2) keygen - log_mem("starting keygen"); + info!("starting keygen"); let fsk: FuncSK = timed_read_async( "keygen", - || abe.keygen(params.clone(), mpk.clone(), msk.clone(), arith_circuit, dir_path.clone()), + || abe.keygen(¶ms, mpk.clone(), msk.clone(), config.arith_height, dir_path.clone()), &mut t_keygen, ) .await; - log_mem("finished keygen"); + info!("finished keygen"); - log_mem("starting writing mpk and fsk files"); + info!("starting writing mpk and fsk files"); mpk.write(dir_path.join(format!("{}.mpk", config.config_id)))?; fsk.write(dir_path.join(format!("{}.fsk", config.config_id)))?; - log_mem("finished writing mpk and fsk files"); + info!("finished writing mpk and fsk files"); Ok(()) } @@ -274,40 +260,35 @@ async fn run_bench_online(config: RunConfig, data_dir: PathBuf) -> Result<()> { config.crt_bits as usize, config.base_bits, ); - let trapdoor_sampler = - DCRTPolyTrapdoorSampler::new(¶ms, config.trapdoor_sigma.expect("trapdoor sigma exist")); + let trapdoor_sigma = config.trapdoor_sigma.expect("trapdoor sigma exist"); let abe = KeyPolicyABE::< DCRTPolyMatrix, DCRTPolyHashSampler, DCRTPolyTrapdoorSampler, DCRTPolyUniformSampler, >::new( - config.limb_bit_size, + config.p_moduli_bits, + config.scale, ¶ms, - config.num_eval_slots, config.knapsack_size, config.e_b_sigma, - trapdoor_sampler, + trapdoor_sigma, ); let mut t_read_mpk = Duration::ZERO; let mut t_enc = Duration::ZERO; let mut t_read_fsk = Duration::ZERO; let mut t_dec = Duration::ZERO; - let num_eval_slots = config.num_eval_slots.unwrap_or(params.ring_dimension() as usize); - log_mem("starting KeyPolicy ABE"); - log_mem("start building arithmetic circuit"); - let arith_circuit = ArithmeticCircuit::::benchmark_multiplication_tree( - ¶ms, - config.limb_bit_size, - num_eval_slots, - config.arith_height as usize, - false, - ); - log_mem("finished building arithmetic circuit"); + let mut inputs = vec![BigUint::ZERO; config.arith_input_size]; + let mut rng = rand::rng(); + for i in 1..inputs.len() { + inputs[i] = gen_biguint_for_modulus(&mut rng, ¶ms.modulus()); + } + + info!("starting KeyPolicy ABE"); // 3) enc - log_mem("starting enc"); + info!("starting enc"); let mpk = timed_read( "read mpk", || { @@ -319,21 +300,11 @@ async fn run_bench_online(config: RunConfig, data_dir: PathBuf) -> Result<()> { }, &mut t_read_mpk, ); - let ct: Ciphertext = timed_read( - "enc", - || { - abe.enc( - params.clone(), - mpk, - &vec![vec![BigUint::ZERO; num_eval_slots]; config.arith_input_size], - &vec![true; num_eval_slots], - ) - }, - &mut t_enc, - ); - log_mem("finished enc"); + let ct: Ciphertext = + timed_read("enc", || abe.enc(¶ms, mpk, &inputs, true), &mut t_enc); + info!("finished enc"); // 4) dec - log_mem("starting dec"); + info!("starting dec"); t_read_mpk = Duration::ZERO; let mpk = timed_read( "read mpk", @@ -358,7 +329,7 @@ async fn run_bench_online(config: RunConfig, data_dir: PathBuf) -> Result<()> { &mut t_read_fsk, ); let bit: bool = - timed_read("dec", || abe.dec(params.clone(), ct, mpk, fsk, arith_circuit), &mut t_dec); - log_mem(format!("finished decryption: result={}", bit)); + timed_read("dec", || abe.dec(¶ms, ct, mpk, fsk, config.arith_height), &mut t_dec); + info!("finished decryption: result={}", bit); Ok(()) } diff --git a/src/abe.rs b/src/abe.rs index 3cffb25..f781b58 100644 --- a/src/abe.rs +++ b/src/abe.rs @@ -2,18 +2,21 @@ use crate::{ ciphertext::Ciphertext, keys::{FuncSK, MasterPK, MasterSK}, }; +use log::info; use mxx::{ - arithmetic::circuit::ArithmeticCircuit, + // arithmetic::circuit::ArithmeticCircuit, bgg::{ encoding::BggEncoding, sampler::{BGGEncodingSampler, BGGPublicKeySampler}, }, + circuit::PolyCircuit, element::PolyElem, - gadgets::crt::encode_modulo_poly, - lookup::lwe_eval::LweBggEncodingPltEvaluator, + gadgets::arith::nested_rns::{NestedRnsPoly, NestedRnsPolyContext, encode_nested_rns_poly}, + lookup::commit_eval::{CommitBGGEncodingPltEvaluator, CommitBGGPubKeyPltEvaluator}, matrix::PolyMatrix, poly::{Poly, PolyParams}, sampler::{DistType, PolyHashSampler, PolyTrapdoorSampler, PolyUniformSampler}, + storage::write::{init_storage_system, wait_for_all_writes}, }; use num_bigint::BigUint; use std::{marker::PhantomData, path::PathBuf, sync::Arc}; @@ -22,63 +25,68 @@ const TAG_BGG_PUBKEY: &[u8] = b"BGG_PUBKEY"; pub struct KeyPolicyABE< M: PolyMatrix + 'static, - SH: PolyHashSampler<[u8; 32], M = M> + Send + Sync, - ST: PolyTrapdoorSampler + Clone + Send + Sync, - SU: PolyUniformSampler + Send + Sync, + HS: PolyHashSampler<[u8; 32], M = M> + Send + Sync, + TS: PolyTrapdoorSampler + Clone + Send + Sync, + US: PolyUniformSampler + Send + Sync, > { - pub e_b_sigma: f64, - pub limb_bit_size: usize, - pub num_crt_limbs: usize, + pub p_moduli_bits: usize, + // pub p_moduli_depth: usize, + pub scale: u64, pub crt_depth: usize, - pub num_eval_slots: usize, pub knapsack_size: Option, - pub trapdoor_sampler: ST, - _sh: PhantomData, - _su: PhantomData, + pub trapdoor_sigma: f64, + pub e_b_sigma: f64, + // pub trapdoor_sampler: TS, + _hs: PhantomData, + _us: PhantomData, + _ts: PhantomData, } impl< M: PolyMatrix + 'static, - SH: PolyHashSampler<[u8; 32], M = M> + Send + Sync, - ST: PolyTrapdoorSampler + Clone + Send + Sync, - SU: PolyUniformSampler + Send + Sync, -> KeyPolicyABE + HS: PolyHashSampler<[u8; 32], M = M> + Send + Sync, + TS: PolyTrapdoorSampler + Clone + Send + Sync, + US: PolyUniformSampler + Send + Sync, +> KeyPolicyABE { pub fn new( - limb_bit_size: usize, + p_moduli_bits: usize, + scale: u64, params: &::Params, - num_eval_slots: Option, knapsack_size: Option, + trapdoor_sigma: f64, e_b_sigma: f64, - trapdoor_sampler: ST, ) -> Self { - let (_, crt_bits, crt_depth) = params.to_crt(); - let num_crt_limbs = crt_bits.div_ceil(limb_bit_size); - let num_eval_slots = num_eval_slots.unwrap_or(params.ring_dimension() as usize); + assert!(p_moduli_bits > 1, "p_moduli_bits must be at least 2 for NestedRns"); + let (_, _, crt_depth) = params.to_crt(); + // NestedRns chooses the number of level-1 moduli as ceil(2 * |q_bits| / (p_bits - 1)) + // let p_moduli_depth = (2 * crt_bits).div_ceil(p_moduli_bits - 1); Self { - limb_bit_size, - num_crt_limbs, + p_moduli_bits, + // p_moduli_depth, + scale, crt_depth, - num_eval_slots, knapsack_size, + trapdoor_sigma, e_b_sigma, - trapdoor_sampler, - _sh: PhantomData, - _su: PhantomData, + _hs: PhantomData, + _us: PhantomData, + _ts: PhantomData, } } pub fn setup( &self, - params: ::Params, + params: &::Params, num_inputs: usize, - ) -> (MasterPK, MasterSK) { + ) -> (MasterPK, MasterSK) { let seed: [u8; 32] = rand::random(); - let (b_trapdoor, b_matrix) = self.trapdoor_sampler.trapdoor(¶ms, 1); + let trapdoor_sampler = TS::new(params, self.trapdoor_sigma); + let (b_trapdoor, b_matrix) = trapdoor_sampler.trapdoor(params, 1); let b_trapdoor = Arc::new(b_trapdoor); let b_matrix = Arc::new(b_matrix); - let uniform_sampler = SU::new(); - let u = uniform_sampler.sample_uniform(¶ms, 1, 1, DistType::FinRingDist); + let uniform_sampler = US::new(); + let u = uniform_sampler.sample_uniform(params, 1, 1, DistType::FinRingDist); let mpk = MasterPK::new(num_inputs, seed, b_matrix, u); let msk = MasterSK::new(b_trapdoor); (mpk, msk) @@ -86,16 +94,21 @@ impl< pub fn enc( &self, - params: ::Params, + params: &::Params, mpk: MasterPK, - inputs: &[Vec], - message: &[bool], + inputs: &[BigUint], + message: bool, ) -> Ciphertext { let num_inputs = inputs.len(); - let uniform_sampler = SU::new(); + assert_eq!( + num_inputs, mpk.num_inputs, + "provided inputs ({num_inputs}) must match mpk.num_inputs ({})", + mpk.num_inputs + ); + let uniform_sampler = US::new(); let s = uniform_sampler.sample_uniform(¶ms, 1, 1, DistType::TernaryDist); let b_col_size = 2 + params.modulus_digits(); - let c_b_error = { + let c_b_error: M = { let first_part = uniform_sampler.sample_uniform( ¶ms, 1, @@ -113,18 +126,23 @@ impl< first_part.concat_columns(&[&second_part, &third_part]) }; let c_b = s.clone() * mpk.b_matrix.as_ref() + &c_b_error; - let bgg_encoding_sampler = BGGEncodingSampler::::new(¶ms, &s.get_row(0), None); + let bgg_encoding_sampler = BGGEncodingSampler::::new(params, &s.get_row(0), None); + // let (_, _, crt_depth) = params.to_crt(); + // let p_moduli_depth = (2 * crt_bits).div_ceil(self.p_moduli_bits - 1); let plaintexts = inputs .iter() - .flat_map(|input| { - assert_eq!(input.len(), self.num_eval_slots); - encode_modulo_poly(self.limb_bit_size, ¶ms, input) - }) + .flat_map(|input| encode_nested_rns_poly(self.p_moduli_bits, params, input)) .collect::>(); - let num_given_input_polys = - num_modulo_poly::(self.limb_bit_size, ¶ms, num_inputs); - let reveal_plaintexts = vec![true; num_given_input_polys + 1]; - let bgg_pubkey_sampler = BGGPublicKeySampler::<_, SH>::new(mpk.seed, 1); + // let expected_plaintexts = mpk.num_inputs * crt_depth * self.p_moduli_depth; + // assert_eq!( + // plaintexts.len(), + // expected_plaintexts, + // "plaintext count ({}) must equal num_inputs * crt_depth * p_moduli_depth ({})", + // plaintexts.len(), + // expected_plaintexts + // ); + let reveal_plaintexts = vec![true; plaintexts.len()]; + let bgg_pubkey_sampler = BGGPublicKeySampler::<_, HS>::new(mpk.seed, 1); let pubkeys = bgg_pubkey_sampler.sample(¶ms, TAG_BGG_PUBKEY, &reveal_plaintexts); let bgg_encodings_no_error = bgg_encoding_sampler.sample(¶ms, &pubkeys, &plaintexts); let encode_col_size = params.modulus_digits(); @@ -161,14 +179,13 @@ impl< } }) .collect::>(); - let ring_dim = params.ring_dimension() as usize; - assert_eq!(message.len(), self.num_eval_slots, "message length must match num_eval_slots",); - let mut message_coeffs: Vec = - message.iter().map(|bit| BigUint::from(*bit as u8)).collect(); - if message_coeffs.len() < ring_dim { - message_coeffs.resize(ring_dim, BigUint::from(0u8)); - } - let message_poly = M::P::from_biguints(¶ms, &message_coeffs); + // let ring_dim = params.ring_dimension() as usize; + // let mut message_coeffs: Vec = + // message.iter().map(|bit| BigUint::from(*bit as u8)).collect(); + // if message_coeffs.len() < ring_dim { + // message_coeffs.resize(ring_dim, BigUint::from(0u8)); + // } + let message_poly = M::P::from_usize_to_constant(¶ms, message as usize); let half_q = ::Elem::half_q(¶ms.modulus()); let half_const = M::P::from_elem_to_constant(¶ms, &half_q); let scaled_message = message_poly * half_const; @@ -185,63 +202,117 @@ impl< pub async fn keygen( &self, - params: ::Params, + params: &::Params, mpk: MasterPK, - msk: MasterSK, - arith_circuit: ArithmeticCircuit, + msk: MasterSK, + height: u32, dir_path: PathBuf, ) -> FuncSK { - let result = arith_circuit - .evaluate_with_bgg_pubkey::( + init_storage_system(dir_path.clone()); + let circuit = { + let mut circuit = PolyCircuit::::new(); + let ctx = Arc::new(NestedRnsPolyContext::setup( + &mut circuit, ¶ms, - mpk.seed, - dir_path.clone(), - 1, - mpk.b_matrix.clone(), - msk.b_trapdoor.clone(), - self.trapdoor_sampler.clone(), - ) - .await; - let a_f = result[0].clone().matrix; - let u_f = self.trapdoor_sampler.preimage_extend( + self.p_moduli_bits, + self.scale, + false, + )); + info!("constructed NestedRnsPolyContext"); + NestedRnsPoly::benchmark_multiplication_tree(ctx, &mut circuit, height as usize, None); + circuit + }; + info!( + "constructed circuit with {} inputs, {:?} gates, and {} non-free depth", + circuit.num_input(), + circuit.count_gates_by_type_vec(), + circuit.non_free_depth() + ); + let tree_base = 2; + let secret_size = mpk.b_matrix.row_size(); + let plt_evaluator = CommitBGGPubKeyPltEvaluator::::setup::( ¶ms, - &msk.b_trapdoor, - &mpk.b_matrix, - &a_f, - &mpk.u, + secret_size, + self.trapdoor_sigma, + tree_base, + mpk.seed, ); + info!("constructed plt_evaluator"); + let reveal_plaintexts = vec![true; circuit.num_input()]; + let bgg_pubkey_sampler = BGGPublicKeySampler::<_, HS>::new(mpk.seed, 1); + let pubkeys = bgg_pubkey_sampler.sample(¶ms, TAG_BGG_PUBKEY, &reveal_plaintexts); + info!("sampled pubkeys"); + info!("starting evaluation of pubkeys"); + let result = circuit.eval(params, &pubkeys[0], &pubkeys[1..], Some(&plt_evaluator)); + info!("finished evaluation of pubkeys"); + info!("starting commit_all_lut_matrices"); + let commit_all_start = std::time::Instant::now(); + plt_evaluator.commit_all_lut_matrices::( + ¶ms, + mpk.b_matrix.as_ref(), + msk.b_trapdoor.as_ref(), + ); + info!("finished commit_all_lut_matrices in {:?}", commit_all_start.elapsed()); + info!("starting wait_for_all_writes"); + wait_for_all_writes(dir_path.clone()).await.unwrap(); + info!("finished wait_for_all_writes"); + + let a_f = result[0].clone().matrix; + let trapdoor_sampler = TS::new(params, self.trapdoor_sigma); + let u_f = + trapdoor_sampler.preimage_extend(¶ms, &msk.b_trapdoor, &mpk.b_matrix, &a_f, &mpk.u); assert_eq!(result.len(), 1); FuncSK { a_f, u_f, dir_path } } pub fn dec( &self, - params: ::Params, + params: &::Params, ct: Ciphertext, mpk: MasterPK, fsk: FuncSK, - arith_circuit: ArithmeticCircuit, + height: u32, ) -> bool { + init_storage_system(fsk.dir_path.clone()); + let circuit = { + let mut circuit = PolyCircuit::::new(); + let ctx = Arc::new(NestedRnsPolyContext::setup( + &mut circuit, + ¶ms, + self.p_moduli_bits, + self.scale, + false, + )); + NestedRnsPoly::benchmark_multiplication_tree(ctx, &mut circuit, height as usize, None); + circuit + }; let encodings = &ct.bgg_encodings[..]; + assert_eq!( + encodings.len(), + circuit.num_input() + 1, + "ciphertext must contain exactly 1 + circuit.num_input() encodings" + ); let dir_path: PathBuf = fsk.dir_path; - let bgg_evaluator = - LweBggEncodingPltEvaluator::::new(mpk.seed, dir_path, ct.c_b.clone()); - let result = arith_circuit.poly_circuit.eval( + let tree_base = 2; + let one_pubkey = encodings[0].pubkey.clone(); + let input_pubkeys = + encodings[1..].iter().map(|encoding| encoding.pubkey.clone()).collect::>(); + let bgg_evaluator = CommitBGGEncodingPltEvaluator::::setup( ¶ms, - &encodings[0], - &encodings[1..], - Some(bgg_evaluator), + tree_base, + mpk.seed, + &circuit, + &one_pubkey, + &input_pubkeys, + &ct.c_b, + &ct.c_b, + &dir_path, ); + let result = circuit.eval(params, &encodings[0], &encodings[1..], Some(&bgg_evaluator)); // 5. Let `c_f := s^T*A_f + e_{c_f}` in $\mathcal{R}_{q}^{1 \times m}$ // be the BGG+ encoding corresponding to the output wire of `poly_circuit`. let v = ct.c_b.concat_columns(&[&result[0].vector]) * fsk.u_f; let z = ct.c_u - &v.get_row(0)[0]; - z.extract_bits_with_threshold(¶ms)[0] + z.extract_bits_with_threshold(params)[0] } } - -fn num_modulo_poly(limb_bit_size: usize, params: &P::Params, num_inputs: usize) -> usize { - let (_, crt_bits, _) = params.to_crt(); - let num_limbs_per_slot = crt_bits.div_ceil(limb_bit_size); - num_inputs * num_limbs_per_slot -} diff --git a/src/simulator.rs b/src/simulator.rs index 3ea87e4..78f8b36 100644 --- a/src/simulator.rs +++ b/src/simulator.rs @@ -1,23 +1,24 @@ use bigdecimal::{BigDecimal, FromPrimitive, One}; +use log::info; pub use mxx::simulator::lattice_estimator::run_lattice_estimator_cli; use mxx::{ - arithmetic::circuit::ArithmeticCircuit, circuit::PolyCircuit, - poly::dcrt::{params::DCRTPolyParams, poly::DCRTPoly}, + gadgets::arith::nested_rns::{NestedRnsPoly, NestedRnsPolyContext}, + poly::{ + PolyParams, + dcrt::{params::DCRTPolyParams, poly::DCRTPoly}, + }, simulator::{ SimulatorContext, + error_norm::*, lattice_estimator::{Distribution, EstimatorCliError}, poly_matrix_norm::PolyMatrixNorm, - wire_norm::NormPltLweEvaluator, }, - utils::log_mem, + utils::bigdecimal_bits_ceil, }; use num_bigint::BigUint; -use rayon::{join, prelude::*}; -use std::sync::{ - Arc, - atomic::{AtomicU32, Ordering}, -}; +use rayon::prelude::*; +use std::sync::Arc; use thiserror::Error; // Logging (replaces println!) // Configure a logger (e.g., env_logger) in the binary/tests to see output. @@ -48,19 +49,127 @@ pub enum SimulatorError { "good log_alpha not found for target_secpar={target_secpar}, ring_dim={ring_dim}, log_q={log_q}, m={m}" )] LogAlphaNotFound { target_secpar: u32, ring_dim: BigUint, log_q: u32, m: BigUint }, - #[error("correctness does not hold: error={e}, q_over_4={q_over_4}")] - NotCorrect { e: BigDecimal, q_over_4: BigDecimal }, + #[error("correctness does not hold: error_bits={e_bits}, q_over_4_bits={q_over_4_bits}")] + NotCorrect { e_bits: u64, q_over_4_bits: u64 }, } // Output (crt_depth, base_bits, log_dim, e_b_sigma, knapsack_size) or None -pub fn bruteforce_params_for_bench_arith_circuit( +// pub fn bruteforce_params_for_bench_arith_circuit( +// target_secpar: u32, +// crt_bits: u32, +// crt_depth_range: (u32, u32), +// base_bits_range: (u32, u32), +// log_dim_range: (u32, u32), +// p_moduli_bits: usize, +// scale: u64, +// height: usize, +// ) -> Option<(u32, u32, u32, f64, u32)> { +// // (cost, crt_depth, base_bits, log_dim, e_b_sigma, knapsack_size) +// let outputs: Vec<(u32, u32, u32, u32, f64, u32)> = +// (base_bits_range.0..=base_bits_range.1) +// .into_par_iter() +// .flat_map(|base_bits| { +// let mut local = Vec::<(u32, u32, u32, u32, f64, u32)>::new(); +// let mut lo = crt_depth_range.0; +// let mut hi = crt_depth_range.1; +// while lo <= hi { +// let crt_depth = lo + ((hi - lo) / 2); +// log::info!("base_bits {base_bits} crt_depth {crt_depth}"); +// let (log_dim, e_b_log_alpha, knapsack_size) = match find_min_ring_dim( +// target_secpar, +// crt_bits, +// crt_depth, +// base_bits, +// log_dim_range, +// ) { +// Ok(result) => result, +// Err(e) => { +// log::info!( +// "Security error with target_secpar = {}, crt_bits = {}, base_bits +// = {}, crt_depth = {}, p_moduli_bits = {}, scale = {}, height = {}: {}", +// target_secpar, crt_bits, base_bits, crt_depth, p_moduli_bits, scale, height, e +// ); // try smaller crt_depth +// if crt_depth == 0 { break; } +// hi = crt_depth - 1; +// continue; +// } +// }; +// log::info!( +// "Found log_dim = {}, e_b_log_alpha = {}, knapsack_size = {}", +// log_dim, +// e_b_log_alpha, +// knapsack_size +// ); +// let ring_dim = (1 << log_dim) as u32; +// let params = DCRTPolyParams::new(ring_dim, crt_depth as usize, crt_bits as +// usize, base_bits); log::info!("params constructed with crt_depth = {}, +// log_dim = {}, base_bits = {}, knapsack_size = {}, e_b_log_alpha = {}", crt_depth, log_dim, +// base_bits, knapsack_size, e_b_log_alpha); let mut circuit = +// PolyCircuit::::new(); let nested_rns_ctx = +// Arc::new(NestedRnsPolyContext::setup(&mut circuit, ¶ms, p_moduli_bits, scale, true)); +// NestedRnsPoly::benchmark_multiplication_tree(nested_rns_ctx, ¶ms, &mut +// circuit, height); // +// ArithmeticCircuit::benchmark_multiplication_tree(¶ms, limb_bit_size, +// num_eval_slots.unwrap_or(ring_dim as usize), height,true); +// log::info!("circuit constructed with crt_depth = {}, log_dim = {}, base_bits = {}, knapsack_size +// = {}, e_b_log_alpha = {}", crt_depth, log_dim, base_bits, knapsack_size, e_b_log_alpha); +// log::info!("circuit size {:?}", circuit.count_gates_by_type_vec()); +// log::info!("poly circuit non_free_depth {}",circuit.non_free_depth()); +// match check_correctness( +// target_secpar, +// params, +// base_bits, +// knapsack_size, +// e_b_log_alpha, +// &circuit, +// ) { +// Ok(cost) => { +// log::info!( +// "Found with target_secpar = {}, crt_bits = {}, base_bits = {}, +// crt_depth = {}, cost = {}", target_secpar, crt_bits, base_bits, +// crt_depth, cost ); +// local.push(( +// cost, +// crt_depth, +// base_bits, +// log_dim, +// 2.0f64.powf( +// crt_bits as f64 * crt_depth as f64 + e_b_log_alpha as f64, +// ), +// knapsack_size, +// )); +// // search smaller crt_depth to continue binary search +// if crt_depth == 0 { break; } +// hi = crt_depth - 1; +// } +// Err(e) => { +// log::info!( +// "Correctness error with target_secpar = {}, crt_bits = {}, +// base_bits = {}, crt_depth = {}: {}", target_secpar, crt_bits, +// base_bits, crt_depth, e ); +// // try larger crt_depth +// lo = crt_depth + 1; +// } +// } +// } +// local +// }) +// .collect(); +// outputs +// .into_iter() +// .min_by(|x, y| x.0.cmp(&y.0)) +// .map(|outs| (outs.1, outs.2, outs.3, outs.4, outs.5)) +// } + +// Output (crt_depth, base_bits, log_dim, e_b_sigma, knapsack_size) or None +pub fn bruteforce_params_for_bench_nested_crt_circuit( target_secpar: u32, crt_bits: u32, crt_depth_range: (u32, u32), base_bits_range: (u32, u32), log_dim_range: (u32, u32), - num_eval_slots: Option, - limb_bit_size: usize, + p_moduli_bits: usize, + scale_bits: u32, height: usize, // circuit: PolyCircuit, ) -> Option<(u32, u32, u32, f64, u32)> { @@ -85,8 +194,8 @@ pub fn bruteforce_params_for_bench_arith_circuit( Ok(result) => result, Err(e) => { log::info!( - "Security error with target_secpar = {}, crt_bits = {}, base_bits = {}, crt_depth = {}, limb_bit_size = {}, height = {}: {}", - target_secpar, crt_bits, base_bits, crt_depth, limb_bit_size, height, e + "Security error with target_secpar = {}, crt_bits = {}, base_bits = {}, crt_depth = {}, p_moduli_bits = {}, height = {}: {}", + target_secpar, crt_bits, base_bits, crt_depth, p_moduli_bits, height, e ); // try smaller crt_depth if crt_depth == 0 { break; } @@ -102,19 +211,25 @@ pub fn bruteforce_params_for_bench_arith_circuit( ); let ring_dim = (1 << log_dim) as u32; let params = DCRTPolyParams::new(ring_dim, crt_depth as usize, crt_bits as usize, base_bits); - let circuit = ArithmeticCircuit::benchmark_multiplication_tree(¶ms, limb_bit_size, num_eval_slots.unwrap_or(ring_dim as usize), height,true); + log::info!("params constructed with crt_depth = {}, log_dim = {}, base_bits = {}, knapsack_size = {}, e_b_log_alpha = {}", crt_depth, log_dim, base_bits, knapsack_size, e_b_log_alpha); + let circuit = { + let mut circuit = PolyCircuit::::new(); + let scale = 1< { log::info!( @@ -206,104 +321,25 @@ fn check_security( base_bits: u32, ) -> Result<(i64, u32), SimulatorError> { let log_q = crt_bits * crt_depth; - let q = BigUint::from(2u32).pow(log_q); let m_g = crt_bits.div_ceil(base_bits) * crt_depth; let m_b = m_g + 2; // The column size of the matrix B (sampled with a trapdoor) is m_b; however, one column is an // identity polynomial, so we need to ignore one column. Additionally, one more uniformly // random matrix is used for encrypting a message in ABE; thus the total column size for // ring-LWE is m_b - 1 + 1 = m_b. - let (log_alpha_res, knapsack_res) = join( - || find_log_alpha_for_ring_lwe(target_secpar, ring_dim, log_q, &BigUint::from(m_b)), - || find_knapsack_size(target_secpar, ring_dim, &q, m_b - 1), - ); + let log_alpha_res = + find_log_alpha_for_ring_lwe(target_secpar, ring_dim, log_q, &BigUint::from(m_b)); + // join( + // || find_log_alpha_for_ring_lwe(target_secpar, ring_dim, log_q, &BigUint::from(m_b)), + // // || find_knapsack_size(target_secpar, ring_dim, &q, m_b - 1), + // ); let log_alpha = log_alpha_res?; log::debug!("found log_alpha_res = {log_alpha}"); - let knapsack_size = knapsack_res?; + let knapsack_size = m_b - 1; log::debug!("found knapsack_size = {knapsack_size}"); Ok((log_alpha, knapsack_size)) } -/// Returns the smallest `knapsack_size` in [1, max_knapsack_size] whose estimated -/// security is at least `target_secpar`, or an error if estimation fails or none found. -/// - `target_secpar`: required minimum security parameter. -/// - `ring_dim`: base ring dimension. -/// - `q`: modulus (as BigUint). -/// - `max_knapsack_size`: upper bound to search (inclusive). -fn find_knapsack_size( - target_secpar: u32, - ring_dim: &BigUint, - q: &BigUint, - max_knapsack_size: u32, -) -> Result { - if max_knapsack_size < 2 { - return Err(SimulatorError::KnapsackNotFound { - target_secpar, - ring_dim: ring_dim.clone(), - max_knapsack_size, - q: q.clone(), - }); - } - - let best = AtomicU32::new(0); - - (2..=max_knapsack_size).into_par_iter().try_for_each( - |knapsack_size| -> Result<(), SimulatorError> { - let current_best = best.load(Ordering::Relaxed); - if current_best != 0 && knapsack_size >= current_best { - return Ok(()); - } - - // Effective LWE dimension n = ring_dim * knapsack_size - ring_dim - let n = ring_dim * BigUint::from(knapsack_size) - ring_dim; - // s_dist = Ternary, e_dist = Ternary, m = n, exact = false (rough) - let secpar = run_lattice_estimator_cli( - &n, - q, - &Distribution::Ternary, - &Distribution::Ternary, - Some(&n), - false, - )?; - log::debug!("called estimator {secpar} in find_knapsack_size for {knapsack_size}"); - - if secpar as u32 >= target_secpar { - let mut observed = best.load(Ordering::Acquire); - while observed == 0 || knapsack_size < observed { - match best.compare_exchange( - observed, - knapsack_size, - Ordering::AcqRel, - Ordering::Acquire, - ) { - Ok(_) => break, - Err(actual) => { - if actual != 0 && knapsack_size >= actual { - break; - } - observed = actual; - } - } - } - } - - Ok(()) - }, - )?; - - let best_value = best.load(Ordering::Relaxed); - if best_value != 0 { - Ok(best_value) - } else { - Err(SimulatorError::KnapsackNotFound { - target_secpar, - ring_dim: ring_dim.clone(), - max_knapsack_size, - q: q.clone(), - }) - } -} - /// Binary-search for the smallest integer `log_alpha` in [-log_q, -1] such that /// the estimated security for ring-LWE with parameters (ring_dim, q=2^log_q, /// s_dist=Ternary, e_dist=DiscreteGaussianAlpha(alpha=2^{-log_alpha}), m) is at @@ -319,7 +355,7 @@ fn find_log_alpha_for_ring_lwe( ) -> Result { // q = 2^{log_q} let q = BigUint::from(1u8) << (log_q as usize); - + let q_dec = BigDecimal::from_biguint(q.clone(), 0); // Search bounds (inclusive) over integer log_alpha. let mut lo: i64 = -(log_q as i64); let mut hi: i64 = 5 - (log_q as i64); @@ -331,7 +367,10 @@ fn find_log_alpha_for_ring_lwe( // alpha = sigma/q = 2^{log_alpha} let alpha = 2f64.powi(mid as i32); // safe for practical parameter sizes - let e_dist = Distribution::DiscreteGaussianAlpha { alpha, mean: None, n: None }; + let stddev = &q_dec * BigDecimal::from_f64(alpha).unwrap(); + let e_dist = + Distribution::DiscreteGaussian { stddev: stddev.to_string(), mean: None, n: None }; + // DiscreteGaussianAlpha { alpha, mean: None, n: None }; // s_dist = Ternary, m = provided, rough estimation let secpar = run_lattice_estimator_cli( @@ -344,7 +383,10 @@ fn find_log_alpha_for_ring_lwe( )?; log::debug!("called estimator {secpar} in find_log_alpha_for_ring_lwe"); - if secpar as u32 >= target_secpar { + if log_q as i64 + mid <= 0 { + // try smaller (more conservative) log_alpha + hi = mid - 1; + } else if secpar as u32 >= target_secpar { found = Some(found.map_or(mid, |cur| cur.min(mid))); // try smaller (more conservative) log_alpha hi = mid - 1; @@ -362,27 +404,45 @@ fn find_log_alpha_for_ring_lwe( }) } +// Compute 2^exponent exactly as a BigDecimal to avoid intermediate f64 overflow. +fn pow_two_bigdecimal(exponent: i64) -> BigDecimal { + if exponent == 0 { + return BigDecimal::one(); + } + let mut result = BigDecimal::one(); + let mut base = BigDecimal::from(2u32); + let mut exp = exponent.unsigned_abs(); + while exp > 0 { + if exp & 1 == 1 { + result = result * &base; + } + exp >>= 1; + if exp > 0 { + base = &base * &base; + } + } + if exponent >= 0 { result } else { BigDecimal::one() / result } +} + fn check_correctness( - target_secpar: u32, - log_dim: u32, - crt_bits: u32, - crt_depth: u32, - base_bits: u32, + params: &DCRTPolyParams, knapsack_size: u32, e_b_log_alpha: i64, + input_norm_bound: BigDecimal, circuit: &PolyCircuit, ) -> Result { let input_size = circuit.num_input(); - let ring_dim = BigUint::from(2u32).pow(log_dim); - let log_q = crt_bits * crt_depth; - let q = BigUint::from(2u32).pow(log_q); - let m_g = (crt_bits.div_ceil(base_bits) * crt_depth) as usize; + let ring_dim = params.ring_dimension(); + let log_q = params.modulus_bits() as u32; + let m_g = params.modulus_digits(); + let base_bits = params.base_bits(); let m_b = m_g + 2; - let e_b_sigma = BigDecimal::from_f64(2f64.powf((log_q as i64 - e_b_log_alpha) as f64)).unwrap(); - let secpar_sqrt = BigDecimal::from_u32(target_secpar).unwrap().sqrt().unwrap(); - let ring_dim_sqrt = BigDecimal::from_biguint(ring_dim.clone(), 0).sqrt().unwrap(); + log::info!("e_b_log_alpha {}", e_b_log_alpha); + let e_b_sigma = pow_two_bigdecimal(i64::from(log_q) + e_b_log_alpha); + log::info!("e_b_sigma {}", e_b_sigma); + let ring_dim_sqrt = BigDecimal::from_u32(ring_dim).unwrap().sqrt().unwrap(); let base = BigDecimal::from_biguint((BigUint::from(1u32)) << base_bits, 0); - let sim_ctx = Arc::new(SimulatorContext::new(secpar_sqrt, ring_dim_sqrt, base, m_g)); + let sim_ctx = Arc::new(SimulatorContext::new(ring_dim_sqrt, base, 1, m_g)); let e_b = PolyMatrixNorm::sample_gauss(sim_ctx.clone(), 1, m_b, e_b_sigma.clone()); let r_mat = PolyMatrixNorm::new( @@ -394,88 +454,87 @@ fn check_correctness( ); let e_a = &e_b * &r_mat; log::info!("before simulation: e_b = {:?}, e_a = {:?}", e_b, e_a); - let out_wire_norms = circuit.simulate_max_h_norm( + let tree_base = 2; + let plt_evaluator = + NormPltCommitEvaluator::new(sim_ctx.clone(), &e_b_sigma, tree_base, circuit); + let preimage_norm = compute_preimage_norm(&sim_ctx.ring_dim_sqrt, m_g as u64, &sim_ctx.base); + let out_errors = circuit.simulate_max_error_norm( sim_ctx.clone(), - BigDecimal::from_u32(crt_bits).unwrap(), + input_norm_bound, input_size, + &e_a.poly_norm.norm, + Some(&plt_evaluator), ); log::info!("after simulation"); - let max_out_wire = out_wire_norms + // let max_out_error = out_errors + // .into_iter() + // .max_by(|a, b| a.matrix_norm.poly_norm.norm.cmp(&b.matrix_norm.poly_norm.norm)) + // .unwrap(); + // let (max_h_top, max_h_bottom) = max_out_error.matrix_norm.poly_norm.split_rows(m_b); + // let max_h_top_bits = bigdecimal_bits_ceil(&max_h_top.poly_norm.norm); + // { + // let s = max_h_top + // .poly_norm + // .norm + // .with_scale_round(0, bigdecimal::RoundingMode::Ceiling) + // .to_string(); + // if let Some(n) = BigUint::parse_bytes(s.as_bytes(), 10) { + // let bytes = n.to_bytes_be(); + // if bytes.is_empty() { + // 0usize + // } else { + // (bytes.len() - 1) * 8 + (8 - bytes[0].leading_zeros() as usize) + // } + // } else { + // 0usize + // } + // }; + // log::info!("max_h_top_bits bits {}", max_h_top_bits); + + // let max_h_bottom_bits = bigdecimal_bits_ceil(&max_h_bottom.poly_norm.norm); + // { + // let s = max_h_bottom + // .poly_norm + // .norm + // .with_scale_round(0, bigdecimal::RoundingMode::Ceiling) + // .to_string(); + // if let Some(n) = BigUint::parse_bytes(s.as_bytes(), 10) { + // let bytes = n.to_bytes_be(); + // if bytes.is_empty() { + // 0usize + // } else { + // (bytes.len() - 1) * 8 + (8 - bytes[0].leading_zeros() as usize) + // } + // } else { + // 0usize + // } + // }; + // log::info!("max_h_bottom_bits bits {}", max_h_bottom_bits); + log::info!("e_b bits {}", bigdecimal_bits_ceil(&e_b.poly_norm.norm)); + log::info!("e_a bits {}", bigdecimal_bits_ceil(&e_a.poly_norm.norm)); + let e_after_eval = out_errors .into_iter() - .max_by(|a, b| a.h_norm.poly_norm.norm.cmp(&b.h_norm.poly_norm.norm)) + .max_by(|a, b| a.matrix_norm.poly_norm.norm.cmp(&b.matrix_norm.poly_norm.norm)) .unwrap(); - let (max_h_top, max_h_bottom) = max_out_wire.h_norm.split_rows(m_b); - let e_after_eval = &e_b * max_h_top + e_a * max_h_bottom; - let plt_eval = NormPltLweEvaluator::new(sim_ctx.clone(), input_size); - let mut preimage_norm_top = plt_eval.preimage1_norm.clone(); - preimage_norm_top.nrow = m_b; - preimage_norm_top.ncol = 1; - let mut preimage_norm_bottom = plt_eval.preimage2_norm.clone(); - preimage_norm_bottom.ncol = 1; + let e_after_eval_bits = bigdecimal_bits_ceil(&e_after_eval.matrix_norm.poly_norm.norm); + log::info!("e_after_eval_bits bits {}", e_after_eval_bits); + + let preimage_norm_top = + PolyMatrixNorm::new(sim_ctx.clone(), m_b, 1, preimage_norm.clone(), None); + let preimage_norm_bottom = + PolyMatrixNorm::new(sim_ctx.clone(), m_g, 1, preimage_norm.clone(), None); let e_u = PolyMatrixNorm::sample_gauss(sim_ctx.clone(), 1, 1, e_b_sigma); - let e_final = &e_b * preimage_norm_top + e_after_eval * preimage_norm_bottom + e_u; - let q_over_4 = BigDecimal::from_biguint(q, 0) / BigDecimal::from_u32(4).unwrap(); - if q_over_4 > e_final.poly_norm.norm { - // Compute bit lengths of q_over_4 and e_final (after rounding up to integer) - let q_over_4_bits = { - let s = q_over_4.with_scale_round(0, bigdecimal::RoundingMode::Ceiling).to_string(); - if let Some(n) = BigUint::parse_bytes(s.as_bytes(), 10) { - let bytes = n.to_bytes_be(); - if bytes.is_empty() { - 0usize - } else { - (bytes.len() - 1) * 8 + (8 - bytes[0].leading_zeros() as usize) - } - } else { - 0usize - } - }; - let e_final_bits = { - let s = e_final - .poly_norm - .norm - .with_scale_round(0, bigdecimal::RoundingMode::Ceiling) - .to_string(); - if let Some(n) = BigUint::parse_bytes(s.as_bytes(), 10) { - let bytes = n.to_bytes_be(); - if bytes.is_empty() { - 0usize - } else { - (bytes.len() - 1) * 8 + (8 - bytes[0].leading_zeros() as usize) - } - } else { - 0usize - } - }; + let e_final = &e_b * preimage_norm_top + e_after_eval.matrix_norm * preimage_norm_bottom + e_u; + let e_final_bits = bigdecimal_bits_ceil(&e_final.poly_norm.norm); + log::info!("e_final_bits bits {}", e_final_bits); - log_mem(format!("q_over_4_bits: {}, e_final_bits: {}", q_over_4_bits, e_final_bits)); - Ok(log_dim * m_g as u32) + let q_over_4 = BigDecimal::from_biguint(params.modulus().as_ref().clone(), 0) / + BigDecimal::from_u32(4).unwrap(); + let q_over_4_bits = bigdecimal_bits_ceil(&q_over_4); + if q_over_4 > e_final.poly_norm.norm { + info!("q_over_4_bits: {}, e_final_bits: {}", q_over_4_bits, e_final_bits); + Ok(log_q * m_g as u32) } else { - Err(SimulatorError::NotCorrect { e: e_final.poly_norm.norm, q_over_4 }) - } -} - -#[cfg(test)] -mod tests { - use super::*; - // Initialize logger for test output - use env_logger; - - #[test] - fn test_bruteforce_params() { - // Initialize env_logger once for tests; ignore if already set. - let _ = env_logger::builder().is_test(true).try_init(); - let params = bruteforce_params_for_bench_arith_circuit( - 100, - 41, - (2, 4), - (15, 18), - (13, 16), - Some(2), - 2, - 3, - ); - assert!(params.is_some()); - println!("params: {:?}", params); + Err(SimulatorError::NotCorrect { e_bits: e_final_bits, q_over_4_bits }) } }