diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md new file mode 100644 index 0000000..8e6df9b --- /dev/null +++ b/ARCHITECTURE.md @@ -0,0 +1,78 @@ +# Architecture + + +## Layers + +The `caring` crate is loosely split into the following different "modules" or traits, +with lower levels being more concrete and higher levels more abstract. + +``` + VM Engine + Protocols | + \__________InteractiveShared + / \ + Communicate Shared + | | + Network Schemes (shamir, spdz, etc.) + | + Connection +``` + +At the lowest level we have the raw `Connection` implementation, +which can be anything that implements `tokio::AsyncRead`/`tokio::AsyncWrite`, +such as the `TcpConnection` or (in-memory) `DuplexConnection`. +This is abstracted away to a `SendBytes`/`RecvBytes` and `Channel`/`SplitChannel` traits, +which allows for any kind of abstract channel for sending and receiving bytes, +such as the multiplexing module `caring::net::mux`. + +A group of connections then form a `Network` which allows for more broad communication by +broadcast, uni(que)cast or tuning to a specific channel. +This enables the traits `Broadcast`, `Unicast`, `Tuneable` forming `Communicate`. +The reasoning behind this allowing protocols to specify if they only need to broadcast/unicast, +and such can specialize in different kinds depending on the scenario. +Furthermore, it allows different schemes of verifiable broadcasts to be swapped in place. + + + + + +## Networking + +> Note +> A lot of functions are defined in terms of items that belong to specific party, +> thus using a `Vec` or slice. The order of these matter, since it will be implied that +> index `i` belongs to player/party `i`. + + +## Schemes + + +### Interactive vs Non-interactive Schemes + +There are two main traits defining a secret sharing scheme, +the first one is the `Shared` which is for schemes such as `shamir` and `feldman` where +the protocols for sharing, reconstruction, etc., does not need interactive communication from the other parties, +but can simply be made locally. + +The `InteractiveShared` trait however does define asynchronous functions for performing sharing and reconstruction +with the aid of the `Communication` trait. +All non-interactive `Shared` schemes can all function as interactive due to a blanket implementation. + + +## Shares + +The share is simply a struct containing (usually) the finite field of the secret shared data. +In the case of Shamir Secret Sharing (and derivatives) the (public) `x` field is left out, +as it is implied by the holder, except for the cases of sharing and reconstruction, +where it is implied by the index. +This is both to minimize the memory footprint of shares and to more strictly enforce checks on the `x`, +as it could be *cheated* with, and we would then require context based parsing for all shares, +which would be difficult. + + +## Protocols + + + +## Testing Framework + diff --git a/Cargo.lock b/Cargo.lock index 65b878d..1ba9b5b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15,45 +15,100 @@ dependencies = [ [[package]] name = "addr2line" -version = "0.21.0" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375" dependencies = [ "gimli", ] [[package]] -name = "adler" -version = "1.0.2" +name = "adler2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" [[package]] -name = "ahash" -version = "0.8.11" +name = "aho-corasick" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ - "cfg-if", - "once_cell", - "version_check", - "zerocopy", + "memchr", ] [[package]] -name = "aho-corasick" -version = "1.1.3" +name = "android-tzdata" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" dependencies = [ - "memchr", + "libc", +] + +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + +[[package]] +name = "anstream" +version = "0.6.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", ] [[package]] -name = "allocator-api2" -version = "0.2.18" +name = "anstyle" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" + +[[package]] +name = "anstyle-parse" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] [[package]] name = "async-backtrace" @@ -79,7 +134,7 @@ checksum = "affbba0d438add06462a0371997575927bc05052f7ec486e7a4ca405c956c3d7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.77", ] [[package]] @@ -101,45 +156,39 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.77", ] [[package]] name = "async-trait" -version = "0.1.80" +version = "0.1.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" +checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.77", ] [[package]] name = "autocfg" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" - -[[package]] -name = "az" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "backtrace" -version = "0.3.71" +version = "0.3.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" dependencies = [ "addr2line", - "cc", "cfg-if", "libc", "miniz_oxide", "object", "rustc-demangle", + "windows-targets 0.52.6", ] [[package]] @@ -153,15 +202,9 @@ dependencies = [ [[package]] name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bitflags" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "bitvec" @@ -185,10 +228,10 @@ dependencies = [ ] [[package]] -name = "bytemuck" -version = "1.15.0" +name = "bumpalo" +version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d6d68c57235a3a081186990eca2867354726650f42f7516ca50c28d6281fd15" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "byteorder" @@ -198,9 +241,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.6.0" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" [[package]] name = "caring" @@ -209,12 +252,10 @@ dependencies = [ "async-backtrace", "async-trait", "bincode", - "castaway", "curve25519-dalek", "derive_more", "digest", "ff", - "fixed", "futures", "futures-concurrency", "group", @@ -228,45 +269,69 @@ dependencies = [ "serde_json", "sha2", "tempfile", + "test-log", "thiserror", "tokio", "tokio-test", "tokio-util", "tracing", + "tracing-forest", + "tracing-serde", + "tracing-subscriber", ] [[package]] -name = "castaway" -version = "0.2.3" +name = "cc" +version = "1.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0abae9be0aaf9ea96a3b1b8b1b55c602ca751eba1b1500220cea4ecbafe7c0d5" +checksum = "07b1695e2c7e8fc85310cde85aeaab7e3097f593c91d209d3f9df76c928100f0" dependencies = [ - "rustversion", + "shlex", ] -[[package]] -name = "cc" -version = "1.0.94" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17f6e324229dc011159fcc089755d1e2e216a90d43a7dea6853ca740b84f35e7" - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-targets 0.52.6", +] + +[[package]] +name = "colorchoice" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" + [[package]] name = "convert_case" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "cpufeatures" -version = "0.2.12" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" dependencies = [ "libc", ] @@ -292,15 +357,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" - -[[package]] -name = "crunchy" -version = "0.2.2" +version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" [[package]] name = "crypto-common" @@ -338,7 +397,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.77", ] [[package]] @@ -356,17 +415,23 @@ dependencies = [ [[package]] name = "derive_more" -version = "0.99.17" +version = "0.99.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" dependencies = [ "convert_case", "proc-macro2", "quote", "rustc_version", - "syn 1.0.109", + "syn 2.0.77", ] +[[package]] +name = "diatomic-waker" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab03c107fafeb3ee9f5925686dbb7a73bc76e3932abb0d2b365cb64b169cf04c" + [[package]] name = "digest" version = "0.10.7" @@ -379,9 +444,30 @@ dependencies = [ [[package]] name = "either" -version = "1.11.0" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[package]] +name = "env_filter" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab" +dependencies = [ + "log", +] + +[[package]] +name = "env_logger" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" +checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "log", +] [[package]] name = "errno" @@ -404,9 +490,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.1.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" [[package]] name = "ff" @@ -439,20 +525,9 @@ dependencies = [ [[package]] name = "fiat-crypto" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c007b1ae3abe1cb6f85a16305acd418b7ca6343b953633fee2b76d8f108b830f" - -[[package]] -name = "fixed" -version = "2.0.0-alpha.27.0" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1bf398c70463a217e213bc751669e4c8509c5676df2444d7a5177722f8ddeaa" -dependencies = [ - "az", - "bytemuck", - "half", -] +checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" [[package]] name = "funty" @@ -475,6 +550,17 @@ dependencies = [ "futures-util", ] +[[package]] +name = "futures-buffered" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91fa130f3777d0d4b0993653c20bc433026d3290627693c4ed1b18dd237357ab" +dependencies = [ + "diatomic-waker", + "futures-core", + "pin-project-lite", +] + [[package]] name = "futures-channel" version = "0.3.30" @@ -487,11 +573,12 @@ dependencies = [ [[package]] name = "futures-concurrency" -version = "7.6.0" +version = "7.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51ee14e256b9143bfafbf2fddeede6f396650bacf95d06fc1b3f2b503df129a0" +checksum = "4b14ac911e85d57c5ea6eef76d7b4d4a3177ecd15f4bea2e61927e9e3823e19f" dependencies = [ "bitvec", + "futures-buffered", "futures-core", "futures-lite", "pin-project", @@ -545,7 +632,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.77", ] [[package]] @@ -603,9 +690,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "libc", @@ -614,9 +701,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.28.1" +version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" [[package]] name = "group" @@ -630,40 +717,55 @@ dependencies = [ ] [[package]] -name = "half" -version = "2.4.1" +name = "hashbrown" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" -dependencies = [ - "cfg-if", - "crunchy", -] +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" [[package]] -name = "hashbrown" -version = "0.14.3" +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "iana-time-zone" +version = "0.1.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" dependencies = [ - "ahash", - "allocator-api2", + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", ] [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "iana-time-zone-haiku" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] [[package]] name = "instant" -version = "0.1.12" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" dependencies = [ "cfg-if", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + [[package]] name = "itertools" version = "0.13.0" @@ -679,17 +781,26 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "lazy_static" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.153" +version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] name = "linux-raw-sys" @@ -699,9 +810,9 @@ checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "lock_api" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -709,9 +820,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.21" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "loom" @@ -737,28 +848,29 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.2" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "miniz_oxide" -version = "0.7.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" dependencies = [ - "adler", + "adler2", ] [[package]] name = "mio" -version = "0.8.11" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" dependencies = [ + "hermit-abi", "libc", "wasi", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -793,28 +905,18 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - [[package]] name = "object" -version = "0.32.2" +version = "0.36.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" dependencies = [ "memchr", ] @@ -833,15 +935,15 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "parking" -version = "2.2.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" [[package]] name = "parking_lot" -version = "0.12.1" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ "lock_api", "parking_lot_core", @@ -849,15 +951,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.9" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -877,7 +979,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.77", ] [[package]] @@ -894,24 +996,27 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "ppv-lite86" -version = "0.2.17" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] [[package]] name = "proc-macro2" -version = "1.0.81" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.36" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -974,18 +1079,18 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.4.1" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" dependencies = [ - "bitflags 1.3.2", + "bitflags", ] [[package]] name = "regex" -version = "1.10.5" +version = "1.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" dependencies = [ "aho-corasick", "memchr", @@ -1027,9 +1132,9 @@ checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" [[package]] name = "rustc-demangle" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "rustc-hash" @@ -1039,20 +1144,20 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustc_version" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" dependencies = [ "semver", ] [[package]] name = "rustix" -version = "0.38.34" +version = "0.38.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" dependencies = [ - "bitflags 2.5.0", + "bitflags", "errno", "libc", "linux-raw-sys", @@ -1085,35 +1190,35 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "semver" -version = "1.0.22" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.198" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.198" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.77", ] [[package]] name = "serde_json" -version = "1.0.121" +version = "1.0.128" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ab380d7d9f22ef3f21ad3e6c1ebe8e4fc7a2000ccba2e4d71fc96f15b2cb609" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" dependencies = [ "itoa", "memchr", @@ -1141,11 +1246,17 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "signal-hook-registry" -version = "1.4.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" dependencies = [ "libc", ] @@ -1167,9 +1278,9 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "socket2" -version = "0.5.6" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", "windows-sys 0.52.0", @@ -1183,9 +1294,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "subtle" -version = "2.5.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" @@ -1200,9 +1311,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.59" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -1217,34 +1328,57 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "tempfile" -version = "3.10.1" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" dependencies = [ "cfg-if", - "fastrand 2.1.0", + "fastrand 2.1.1", + "once_cell", "rustix", - "windows-sys 0.52.0", + "windows-sys 0.59.0", +] + +[[package]] +name = "test-log" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dffced63c2b5c7be278154d76b479f9f9920ed34e7574201407f0b14e2bbb93" +dependencies = [ + "env_logger", + "test-log-macros", + "tracing-subscriber", +] + +[[package]] +name = "test-log-macros" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5999e24eaa32083191ba4e425deb75cdf25efefabe5aaccb7446dd0d4122a3f5" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.77", ] [[package]] name = "thiserror" -version = "1.0.58" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.58" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.77", ] [[package]] @@ -1259,39 +1393,38 @@ dependencies = [ [[package]] name = "tokio" -version = "1.37.0" +version = "1.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" dependencies = [ "backtrace", "bytes", "libc", "mio", - "num_cpus", "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "tokio-macros" -version = "2.2.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.77", ] [[package]] name = "tokio-stream" -version = "0.1.15" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" dependencies = [ "futures-core", "pin-project-lite", @@ -1313,9 +1446,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.10" +version = "0.7.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" dependencies = [ "bytes", "futures-core", @@ -1326,7 +1459,6 @@ dependencies = [ "pin-project-lite", "slab", "tokio", - "tracing", ] [[package]] @@ -1348,7 +1480,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.77", ] [[package]] @@ -1361,6 +1493,23 @@ dependencies = [ "valuable", ] +[[package]] +name = "tracing-forest" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee40835db14ddd1e3ba414292272eddde9dad04d3d4b65509656414d1c42592f" +dependencies = [ + "ansi_term", + "chrono", + "serde", + "smallvec", + "thiserror", + "tokio", + "tracing", + "tracing-subscriber", + "uuid", +] + [[package]] name = "tracing-log" version = "0.2.0" @@ -1372,6 +1521,16 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "tracing-serde" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1" +dependencies = [ + "serde", + "tracing-core", +] + [[package]] name = "tracing-subscriber" version = "0.3.18" @@ -1398,9 +1557,25 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "uuid" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314" +dependencies = [ + "getrandom", + "serde", +] [[package]] name = "valuable" @@ -1410,15 +1585,15 @@ checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "waker-fn" -version = "1.1.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3c4517f54858c779bbcbf228f4fca63d121bf85fbecb2dc578cdf4a39395690" +checksum = "317211a0dc0ceedd78fb2ca9a44aed3d7b9b26f81870d485c07122b4350673b7" [[package]] name = "wasi" @@ -1426,6 +1601,61 @@ 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.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.77", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.77", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + [[package]] name = "winapi" version = "0.3.9" @@ -1458,12 +1688,12 @@ dependencies = [ ] [[package]] -name = "windows-sys" -version = "0.48.0" +name = "windows-core" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -1472,7 +1702,16 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.5", + "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]] @@ -1492,18 +1731,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", + "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]] @@ -1514,9 +1753,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" @@ -1526,9 +1765,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" @@ -1538,15 +1777,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" @@ -1556,9 +1795,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" @@ -1568,9 +1807,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" @@ -1580,9 +1819,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" @@ -1592,9 +1831,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "wyz" @@ -1607,26 +1846,27 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.7.32" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ + "byteorder", "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.32" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.77", ] [[package]] name = "zeroize" -version = "1.7.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/Cargo.toml b/Cargo.toml index 6052155..81f865b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,11 +10,9 @@ license = "MIT OR Apache-2.0" async-backtrace = "0.2.6" async-trait = "0.1.80" bincode = "1.3.3" -castaway = "0.2.3" derive_more = "0.99.17" digest = "0.10.7" ff = { version = "0.13.0", features = ["derive"] } -fixed = "2.0.0-alpha.11" futures = "0.3.28" futures-concurrency = "7.6.0" group = "0.13.0" @@ -28,9 +26,13 @@ serde = { version = "1.0.188", features = ["derive"] } thiserror = "1.0.50" tokio = { version = "1.32.0", features = ["full"] } tokio-util = { version = "0.7.9", features = ["io", "net", "io-util", "codec", "full"] } -tracing = "0.1.40" +tracing = { version = "0.1.40", features = ["max_level_debug"]} +tracing-serde = "0.1.3" [dev-dependencies] +tracing-subscriber = "0.3.18" +tracing-forest = { version = "0.1.6", features = ["full"] } +test-log = { version = "0.2.16", features = ["trace"]} serde_json = "1.0.121" tempfile = "3.10.1" tokio-test = "0.4.4" diff --git a/README.md b/README.md index c173c16..42938ae 100644 --- a/README.md +++ b/README.md @@ -9,16 +9,18 @@ and be generic in the underlying protocols and settings a givens scheme can use. Currently, we are working with the following schemes: - Shamir Secret Sharing (complete) - Feldman's Secret Sharing (lack. multiplication) +- SPDZ (only online phase) - Pedersen Secret Sharing (lack. addition + multiplication) - Rep3 (addition) -- SPDZ (wip) *Note*: This is prototype software and not suited to be used in security critical applications as of yet. ## Subprojects -The base crate here is to provide a library with secret-sharing and other MPC functionality. -The project contains a sample of a consuming library [`wecare`](./wecare) provinding a subroutine for the securely computing a simple sum. -This is further used by [`ccare`](./ccare) and [`pycare`]('./pycare') for C and Python bindings respectively. +[`wecare`](./wecare) provides an abstraction over `caring` by removing the generics and baking the finite fields in directly, +which can then be selected at runtime. + +[`pycare`](./pycare) takes `wecare` and provides python bindings to it allowing easily secret sharing in Python. +See [pycare/examples](./pycare/examples) for example applications. # Inspiration diff --git a/ccare/.gitignore b/ccare/.gitignore deleted file mode 100644 index 8a9d720..0000000 --- a/ccare/.gitignore +++ /dev/null @@ -1,73 +0,0 @@ -/target -.env/ - -# Byte-compiled / optimized / DLL files -__pycache__/ -.pytest_cache/ -*.py[cod] - -# C extensions -*.so - -# Distribution / packaging -.Python -.venv/ -env/ -bin/ -build/ -develop-eggs/ -dist/ -eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -include/ -man/ -venv/ -*.egg-info/ -.installed.cfg -*.egg - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt -pip-selfcheck.json - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.cache -nosetests.xml -coverage.xml - -# Translations -*.mo - -# Mr Developer -.mr.developer.cfg -.project -.pydevproject - -# Rope -.ropeproject - -# Django stuff: -*.log -*.pot - -.DS_Store - -# Sphinx documentation -docs/_build/ - -# PyCharm -.idea/ - -# VSCode -.vscode/ - -# Pyenv -.python-version diff --git a/ccare/Cargo.lock b/ccare/Cargo.lock deleted file mode 100644 index 1aa4d44..0000000 --- a/ccare/Cargo.lock +++ /dev/null @@ -1,1725 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addchain" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b2e69442aa5628ea6951fa33e24efe8313f4321a91bd729fc2f75bdfc858570" -dependencies = [ - "num-bigint", - "num-integer", - "num-traits", -] - -[[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.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" -dependencies = [ - "cfg-if", - "once_cell", - "version_check", - "zerocopy", -] - -[[package]] -name = "aho-corasick" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" -dependencies = [ - "memchr", -] - -[[package]] -name = "allocator-api2" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" - -[[package]] -name = "async-backtrace" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dcb391558246d27a13f195c1e3a53eda422270fdd452bd57a5aa9c1da1bb198" -dependencies = [ - "async-backtrace-attributes", - "dashmap", - "futures", - "loom", - "once_cell", - "pin-project-lite", - "rustc-hash", - "static_assertions", -] - -[[package]] -name = "async-backtrace-attributes" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "affbba0d438add06462a0371997575927bc05052f7ec486e7a4ca405c956c3d7" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.59", -] - -[[package]] -name = "async-trait" -version = "0.1.80" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.59", -] - -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi 0.1.19", - "libc", - "winapi", -] - -[[package]] -name = "autocfg" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" - -[[package]] -name = "az" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973" - -[[package]] -name = "backtrace" -version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "bincode" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" -dependencies = [ - "serde", -] - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - -[[package]] -name = "bytemuck" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d6d68c57235a3a081186990eca2867354726650f42f7516ca50c28d6281fd15" - -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - -[[package]] -name = "caring" -version = "0.1.0" -dependencies = [ - "async-backtrace", - "async-trait", - "bincode", - "derive_more", - "digest", - "ff", - "fixed", - "futures", - "futures-concurrency", - "group", - "itertools", - "num-traits", - "overload", - "rand", - "rand_chacha", - "rayon", - "serde", - "thiserror", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "cbindgen" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da6bc11b07529f16944307272d5bd9b22530bc7d05751717c9d416586cedab49" -dependencies = [ - "clap", - "heck", - "indexmap", - "log", - "proc-macro2", - "quote", - "serde", - "serde_json", - "syn 1.0.109", - "tempfile", - "toml", -] - -[[package]] -name = "cc" -version = "1.0.94" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17f6e324229dc011159fcc089755d1e2e216a90d43a7dea6853ca740b84f35e7" - -[[package]] -name = "ccare" -version = "0.1.0" -dependencies = [ - "cbindgen", - "curve25519-dalek", - "fixed", - "rand", - "tokio", - "wecare", -] - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "clap" -version = "3.2.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" -dependencies = [ - "atty", - "bitflags 1.3.2", - "clap_lex", - "indexmap", - "strsim", - "termcolor", - "textwrap", -] - -[[package]] -name = "clap_lex" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" -dependencies = [ - "os_str_bytes", -] - -[[package]] -name = "convert_case" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" - -[[package]] -name = "cpufeatures" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" -dependencies = [ - "libc", -] - -[[package]] -name = "crossbeam-deque" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" -dependencies = [ - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" -dependencies = [ - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" - -[[package]] -name = "crunchy" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" - -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "curve25519-dalek" -version = "4.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" -dependencies = [ - "cfg-if", - "cpufeatures", - "curve25519-dalek-derive", - "fiat-crypto", - "group", - "rand_core", - "rustc_version", - "serde", - "subtle", - "zeroize", -] - -[[package]] -name = "curve25519-dalek-derive" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.59", -] - -[[package]] -name = "dashmap" -version = "5.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" -dependencies = [ - "cfg-if", - "hashbrown 0.14.3", - "lock_api", - "once_cell", - "parking_lot_core", -] - -[[package]] -name = "derive_more" -version = "0.99.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" -dependencies = [ - "convert_case", - "proc-macro2", - "quote", - "rustc_version", - "syn 1.0.109", -] - -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "crypto-common", -] - -[[package]] -name = "either" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" - -[[package]] -name = "enum_dispatch" -version = "0.3.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa18ce2bc66555b3218614519ac839ddb759a7d6720732f979ef8d13be147ecd" -dependencies = [ - "once_cell", - "proc-macro2", - "quote", - "syn 2.0.59", -] - -[[package]] -name = "errno" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" -dependencies = [ - "instant", -] - -[[package]] -name = "fastrand" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "byteorder", - "ff_derive", - "rand_core", - "subtle", -] - -[[package]] -name = "ff_derive" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9f54704be45ed286151c5e11531316eaef5b8f5af7d597b806fdb8af108d84a" -dependencies = [ - "addchain", - "cfg-if", - "num-bigint", - "num-integer", - "num-traits", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "fiat-crypto" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c007b1ae3abe1cb6f85a16305acd418b7ca6343b953633fee2b76d8f108b830f" - -[[package]] -name = "fixed" -version = "2.0.0-alpha.27.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1bf398c70463a217e213bc751669e4c8509c5676df2444d7a5177722f8ddeaa" -dependencies = [ - "az", - "bytemuck", - "half", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-concurrency" -version = "7.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51ee14e256b9143bfafbf2fddeede6f396650bacf95d06fc1b3f2b503df129a0" -dependencies = [ - "bitvec", - "futures-core", - "futures-lite", - "pin-project", - "slab", - "smallvec", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-lite" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" -dependencies = [ - "fastrand 1.9.0", - "futures-core", - "futures-io", - "memchr", - "parking", - "pin-project-lite", - "waker-fn", -] - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.59", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "generator" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc16584ff22b460a382b7feec54b23d2908d858152e5739a120b949293bd74e" -dependencies = [ - "cc", - "libc", - "log", - "rustversion", - "windows", -] - -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - -[[package]] -name = "getrandom" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "half" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" -dependencies = [ - "cfg-if", - "crunchy", -] - -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - -[[package]] -name = "hashbrown" -version = "0.14.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" -dependencies = [ - "ahash", - "allocator-api2", -] - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "indexmap" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" -dependencies = [ - "autocfg", - "hashbrown 0.12.3", -] - -[[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "itertools" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" -dependencies = [ - "either", -] - -[[package]] -name = "itoa" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "libc" -version = "0.2.153" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" - -[[package]] -name = "linux-raw-sys" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" - -[[package]] -name = "lock_api" -version = "0.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "log" -version = "0.4.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" - -[[package]] -name = "loom" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff50ecb28bb86013e935fb6683ab1f6d3a20016f123c76fd4c27470076ac30f5" -dependencies = [ - "cfg-if", - "generator", - "scoped-tls", - "tracing", - "tracing-subscriber", -] - -[[package]] -name = "matchers" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" -dependencies = [ - "regex-automata 0.1.10", -] - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "nu-ansi-term" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" -dependencies = [ - "overload", - "winapi", -] - -[[package]] -name = "num-bigint" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f6f7833f2cbf2360a6cfd58cd41a53aa7a90bd4c202f5b1c7dd2ed73c57b2c3" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-integer" -version = "0.1.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" -dependencies = [ - "num-traits", -] - -[[package]] -name = "num-traits" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" -dependencies = [ - "autocfg", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi 0.3.9", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - -[[package]] -name = "os_str_bytes" -version = "6.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" - -[[package]] -name = "overload" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" - -[[package]] -name = "parking" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" - -[[package]] -name = "parking_lot" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.48.5", -] - -[[package]] -name = "pin-project" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.59", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "ppv-lite86" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" - -[[package]] -name = "proc-macro2" -version = "1.0.81" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] -name = "rayon" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" -dependencies = [ - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" -dependencies = [ - "crossbeam-deque", - "crossbeam-utils", -] - -[[package]] -name = "redox_syscall" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" -dependencies = [ - "bitflags 1.3.2", -] - -[[package]] -name = "regex" -version = "1.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata 0.4.6", - "regex-syntax 0.8.3", -] - -[[package]] -name = "regex-automata" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" -dependencies = [ - "regex-syntax 0.6.29", -] - -[[package]] -name = "regex-automata" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax 0.8.3", -] - -[[package]] -name = "regex-syntax" -version = "0.6.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" - -[[package]] -name = "regex-syntax" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" - -[[package]] -name = "rustc-demangle" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" - -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - -[[package]] -name = "rustc_version" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" -dependencies = [ - "semver", -] - -[[package]] -name = "rustix" -version = "0.38.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" -dependencies = [ - "bitflags 2.5.0", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] - -[[package]] -name = "rustversion" -version = "1.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" - -[[package]] -name = "ryu" -version = "1.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" - -[[package]] -name = "scoped-tls" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "semver" -version = "1.0.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" - -[[package]] -name = "serde" -version = "1.0.198" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.198" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.59", -] - -[[package]] -name = "serde_json" -version = "1.0.116" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "sharded-slab" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "signal-hook-registry" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" -dependencies = [ - "libc", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - -[[package]] -name = "strsim" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" - -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.59" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - -[[package]] -name = "tempfile" -version = "3.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" -dependencies = [ - "cfg-if", - "fastrand 2.0.2", - "rustix", - "windows-sys 0.52.0", -] - -[[package]] -name = "termcolor" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "textwrap" -version = "0.16.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" - -[[package]] -name = "thiserror" -version = "1.0.58" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.58" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.59", -] - -[[package]] -name = "thread_local" -version = "1.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" -dependencies = [ - "cfg-if", - "once_cell", -] - -[[package]] -name = "tokio" -version = "1.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.59", -] - -[[package]] -name = "tokio-util" -version = "0.7.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" -dependencies = [ - "bytes", - "futures-core", - "futures-io", - "futures-sink", - "futures-util", - "hashbrown 0.14.3", - "pin-project-lite", - "slab", - "tokio", - "tracing", -] - -[[package]] -name = "toml" -version = "0.5.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" -dependencies = [ - "serde", -] - -[[package]] -name = "tracing" -version = "0.1.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" -dependencies = [ - "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.59", -] - -[[package]] -name = "tracing-core" -version = "0.1.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" -dependencies = [ - "once_cell", - "valuable", -] - -[[package]] -name = "tracing-log" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" -dependencies = [ - "log", - "once_cell", - "tracing-core", -] - -[[package]] -name = "tracing-subscriber" -version = "0.3.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" -dependencies = [ - "matchers", - "nu-ansi-term", - "once_cell", - "regex", - "sharded-slab", - "smallvec", - "thread_local", - "tracing", - "tracing-core", - "tracing-log", -] - -[[package]] -name = "typenum" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "valuable" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "waker-fn" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3c4517f54858c779bbcbf228f4fca63d121bf85fbecb2dc578cdf4a39395690" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wecare" -version = "0.1.0" -dependencies = [ - "caring", - "curve25519-dalek", - "enum_dispatch", - "fixed", - "rand", - "tokio", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-util" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" -dependencies = [ - "winapi", -] - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "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 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.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_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[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_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[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_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[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_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zerocopy" -version = "0.7.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" -dependencies = [ - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.59", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/ccare/Cargo.toml b/ccare/Cargo.toml deleted file mode 100644 index 8061de8..0000000 --- a/ccare/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "ccare" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[lib] -name = "caring" -crate-type = ["cdylib"] - -[profile.release] -debug = true - -[dependencies] -wecare = { path = "../wecare" } -tokio = { version = "1.33.0", features = ["full"] } -curve25519-dalek = { version = "4.1.1", features = ["group", "serde"] } -rand = "0.8.5" -fixed = "2.0.0-alpha.11" - -[build-dependencies] -cbindgen = "0.26.0" diff --git a/ccare/README.md b/ccare/README.md deleted file mode 100644 index c99ff7a..0000000 --- a/ccare/README.md +++ /dev/null @@ -1,19 +0,0 @@ -

C Bindings

-

Lingua Franca MPC Routines

- - -## Build -```sh -cargo build (--release) -``` - - -## Generating headers -Headers can be generated using [`cbindgen`](https://github.com/mozilla/cbindgen). -```sh -cbindgen --lang=C --output=target/release/libcaring.h -``` - -## Sample Matlab Code -A sample matlab code can be found in [test.m](./test.m) which showcases how to consume the C library. -Note that the script expects the library and headers to be placed in `target/release`. diff --git a/ccare/examples/test.m b/ccare/examples/test.m deleted file mode 100644 index 92ba659..0000000 --- a/ccare/examples/test.m +++ /dev/null @@ -1,66 +0,0 @@ -addpath("./target/release"); -[err, warn] = loadlibrary("libcaring"); - -me = '127.0.0.1:1234'; -others = {'127.0.0.1:1235'}; - -[err] = calllib("libcaring", "care_setup", me, others, length(others)) -if (err ~= 0) - fprintf("Got a nasty error:\n error code %d", err); - quit(err); -end - -res = care_sum(2.5); -fprintf("2.5 - 5 = %f\n", res); - -ins = [2.5, 3.5]; -res = care_sum_many(ins); -fprintf("[2.5, 3.5] + [3.2, 0.5] = [%f, %f]\n", res(1), res(2)) - -res = care_sum(3.14159265359); -fprintf("pi + pi = %f\n", res); - -res = care_sum(3.14159265359); -fprintf("pi - pi = %f\n", res); - -res = care_sum(-1.0); -fprintf("-1 - 2 = %f\n", res); - -res = care_sum(1111.1111); -fprintf("1111.1111 + 2222.2222 = %f\n", res); - -res = care_sum(1111.1111); -fprintf("1111.1111 - 2222.2222 = %f\n", res); - -res = care_sum(3.23e13); -fprintf("3.23e13 + 5.32e13 = %f\n", res); - -res = care_sum(0.0); -fprintf("0 + 0 = %f\n", res); - -res = care_sum(0.01); -fprintf("0.01 + 0.02 = %f\n", res); - -calllib("libcaring", "care_takedown") - -unloadlibrary("libcaring"); - -function [res] = care_sum(a) - [s] = calllib("libcaring", "care_sum", a); - if s == NaN - quit(-1); - end - res = s; -end - -function [res] = care_sum_many(a) - len = length(a); - init = zeros(len, 1); - ptr = libpointer('doublePtr', init); - [err] = calllib("libcaring", "care_sum_many", a, ptr, len); - res = ptr.value; - if err ~= 0 - fprintf("Quitting with %d\n", err) - quit(err); - end -end diff --git a/ccare/src/lib.rs b/ccare/src/lib.rs deleted file mode 100644 index d97a99f..0000000 --- a/ccare/src/lib.rs +++ /dev/null @@ -1,107 +0,0 @@ -use core::slice; -use std::{ffi::{c_char, CStr}, fs::File, panic, sync::Mutex}; - -use wecare::SpdzEngine; - -static ENGINE : Mutex> = Mutex::new(None); - - -/// Setup a MPC engine with address `my_addr` connected to the parties with addresses in the -/// array `others`. -/// -/// This returns an integer returning zero on no errors otherwise. -/// -/// # Error Codes -/// 1. preproc malformed -/// 2. could not open preproc file -/// 3. my_addr malformed -/// 4. others malformed -/// 5. something went wrong in setup_engine, bad address format? -/// -/// # Safety -/// Strings must null terminated and the array have length `len` -#[no_mangle] -pub unsafe extern "C" fn care_setup(preproc: *const c_char, my_addr: *const c_char, others: *const *const c_char, len: usize) -> i32 { - let file = unsafe { CStr::from_ptr(preproc) }; - let Ok(file) = file.to_str() else { - return 1; - }; - let Ok(mut file) = File::open(file) else { - return 2; - }; - - let my_addr = unsafe { CStr::from_ptr(my_addr) }; - let Ok(my_addr) = my_addr.to_str() else { - return 3; - }; - - let Ok(others) = (unsafe { - let others = slice::from_raw_parts(others, len); - let others: Result, _> = others - .iter() - .map(|&ptr| CStr::from_ptr(ptr)) - .map(|cstr| cstr.to_str()) - .collect(); - others - }) else { - return 4; - }; - let Ok(engine) = SpdzEngine::spdz(my_addr, &others, &mut file) else { - return 5; - }; - *ENGINE.lock().unwrap() = Some(engine); - 0 -} - -/// Run a sum procedure in which each party supplies a double floating point -/// -/// Returns `NaN` on unknown panics. -/// -#[no_mangle] -pub extern "C" fn care_sum(a: f64) -> f64 { - - let result = panic::catch_unwind(|| { - let engine = &mut ENGINE.lock().unwrap(); - let engine = engine.as_mut().unwrap(); - engine.mpc_sum(&[a]) - }); - let Ok(result) = result else { - return f64::NAN; - }; - let Some(result) = result else { - return -1.0; - }; - result[0] -} - -/// Compute many sums (vectorized) -/// -/// # Safety -/// The `buf` pointer must have length `len`. -/// -/// Returns `-1` on unknown panics. -/// -#[no_mangle] -pub unsafe extern "C" fn care_sum_many(buf: *const f64, des: *mut f64, len: usize) -> i32 { - let input: &[_] = unsafe { slice::from_raw_parts(buf, len) }; - let result = panic::catch_unwind(|| { - let engine = &mut ENGINE.lock().unwrap(); - let engine = engine.as_mut().unwrap(); - engine.mpc_sum(input) - }); - let Ok(res) = result else { - return -1; - }; - let Some(res) = res else { - return 1; - }; - let res = res.as_slice().as_ptr(); - unsafe { std::ptr::copy_nonoverlapping(res, des, len) }; - 0 -} - -/// Takedown the MPC engine, freeing the memory and dropping the connections -#[no_mangle] -pub extern "C" fn care_takedown() { - ENGINE.lock().unwrap().as_mut().take(); -} diff --git a/pycare/Cargo.lock b/pycare/Cargo.lock index 869d4d8..b8707fa 100644 --- a/pycare/Cargo.lock +++ b/pycare/Cargo.lock @@ -15,30 +15,18 @@ dependencies = [ [[package]] name = "addr2line" -version = "0.21.0" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375" 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.8.11" +name = "adler2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" -dependencies = [ - "cfg-if", - "once_cell", - "version_check", - "zerocopy", -] +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" [[package]] name = "aho-corasick" @@ -49,12 +37,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "allocator-api2" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" - [[package]] name = "async-backtrace" version = "0.2.7" @@ -79,25 +61,25 @@ checksum = "affbba0d438add06462a0371997575927bc05052f7ec486e7a4ca405c956c3d7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.77", ] [[package]] name = "async-trait" -version = "0.1.80" +version = "0.1.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" +checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.77", ] [[package]] name = "autocfg" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "az" @@ -107,17 +89,17 @@ checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973" [[package]] name = "backtrace" -version = "0.3.71" +version = "0.3.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" dependencies = [ "addr2line", - "cc", "cfg-if", "libc", "miniz_oxide", "object", "rustc-demangle", + "windows-targets 0.52.6", ] [[package]] @@ -131,9 +113,9 @@ dependencies = [ [[package]] name = "bitflags" -version = "1.3.2" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "bitvec" @@ -158,9 +140,9 @@ dependencies = [ [[package]] name = "bytemuck" -version = "1.15.0" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d6d68c57235a3a081186990eca2867354726650f42f7516ca50c28d6281fd15" +checksum = "94bbb0ad554ad961ddc5da507a12a29b14e4ae5bda06b19f575a3e6079d2e2ae" [[package]] name = "byteorder" @@ -170,9 +152,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.6.0" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" [[package]] name = "caring" @@ -181,11 +163,9 @@ dependencies = [ "async-backtrace", "async-trait", "bincode", - "castaway", "derive_more", "digest", "ff", - "fixed", "futures", "futures-concurrency", "group", @@ -200,23 +180,18 @@ dependencies = [ "tokio", "tokio-util", "tracing", + "tracing-serde", ] [[package]] -name = "castaway" -version = "0.2.3" +name = "cc" +version = "1.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0abae9be0aaf9ea96a3b1b8b1b55c602ca751eba1b1500220cea4ecbafe7c0d5" +checksum = "07b1695e2c7e8fc85310cde85aeaab7e3097f593c91d209d3f9df76c928100f0" dependencies = [ - "rustversion", + "shlex", ] -[[package]] -name = "cc" -version = "1.0.94" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17f6e324229dc011159fcc089755d1e2e216a90d43a7dea6853ca740b84f35e7" - [[package]] name = "cfg-if" version = "1.0.0" @@ -231,9 +206,9 @@ checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" [[package]] name = "cpufeatures" -version = "0.2.12" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" dependencies = [ "libc", ] @@ -259,9 +234,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.19" +version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" [[package]] name = "crunchy" @@ -305,7 +280,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.77", ] [[package]] @@ -323,17 +298,23 @@ dependencies = [ [[package]] name = "derive_more" -version = "0.99.17" +version = "0.99.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" dependencies = [ "convert_case", "proc-macro2", "quote", "rustc_version", - "syn 1.0.109", + "syn 2.0.77", ] +[[package]] +name = "diatomic-waker" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab03c107fafeb3ee9f5925686dbb7a73bc76e3932abb0d2b365cb64b169cf04c" + [[package]] name = "digest" version = "0.10.7" @@ -346,21 +327,9 @@ dependencies = [ [[package]] name = "either" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" - -[[package]] -name = "enum_dispatch" -version = "0.3.13" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa18ce2bc66555b3218614519ac839ddb759a7d6720732f979ef8d13be147ecd" -dependencies = [ - "once_cell", - "proc-macro2", - "quote", - "syn 2.0.59", -] +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "fastrand" @@ -402,9 +371,9 @@ dependencies = [ [[package]] name = "fiat-crypto" -version = "0.2.7" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c007b1ae3abe1cb6f85a16305acd418b7ca6343b953633fee2b76d8f108b830f" +checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" [[package]] name = "fixed" @@ -438,6 +407,17 @@ dependencies = [ "futures-util", ] +[[package]] +name = "futures-buffered" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91fa130f3777d0d4b0993653c20bc433026d3290627693c4ed1b18dd237357ab" +dependencies = [ + "diatomic-waker", + "futures-core", + "pin-project-lite", +] + [[package]] name = "futures-channel" version = "0.3.30" @@ -450,11 +430,12 @@ dependencies = [ [[package]] name = "futures-concurrency" -version = "7.6.0" +version = "7.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51ee14e256b9143bfafbf2fddeede6f396650bacf95d06fc1b3f2b503df129a0" +checksum = "4b14ac911e85d57c5ea6eef76d7b4d4a3177ecd15f4bea2e61927e9e3823e19f" dependencies = [ "bitvec", + "futures-buffered", "futures-core", "futures-lite", "pin-project", @@ -508,7 +489,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.77", ] [[package]] @@ -566,9 +547,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "libc", @@ -577,9 +558,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.28.1" +version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" [[package]] name = "group" @@ -604,13 +585,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.3" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" -dependencies = [ - "ahash", - "allocator-api2", -] +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" [[package]] name = "heck" @@ -632,9 +609,9 @@ checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5" [[package]] name = "instant" -version = "0.1.12" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" dependencies = [ "cfg-if", ] @@ -650,21 +627,21 @@ dependencies = [ [[package]] name = "lazy_static" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.153" +version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] name = "lock_api" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -672,9 +649,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.21" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "loom" @@ -700,9 +677,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.2" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "memoffset" @@ -715,22 +692,23 @@ dependencies = [ [[package]] name = "miniz_oxide" -version = "0.7.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" dependencies = [ - "adler", + "adler2", ] [[package]] name = "mio" -version = "0.8.11" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" dependencies = [ + "hermit-abi", "libc", "wasi", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -765,28 +743,18 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - [[package]] name = "object" -version = "0.32.2" +version = "0.36.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" dependencies = [ "memchr", ] @@ -805,15 +773,15 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "parking" -version = "2.2.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" [[package]] name = "parking_lot" -version = "0.12.1" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ "lock_api", "parking_lot_core", @@ -821,15 +789,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.9" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -849,7 +817,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.77", ] [[package]] @@ -866,21 +834,24 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "portable-atomic" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0" +checksum = "da544ee218f0d287a911e9c99a39a8c9bc8fcad3cb8db5959940044ecfc67265" [[package]] name = "ppv-lite86" -version = "0.2.17" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] [[package]] name = "proc-macro2" -version = "1.0.81" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] @@ -890,14 +861,15 @@ name = "pycare" version = "0.1.0" dependencies = [ "pyo3", + "tracing-subscriber", "wecare", ] [[package]] name = "pyo3" -version = "0.22.2" +version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "831e8e819a138c36e212f3af3fd9eeffed6bf1510a805af35b0edee5ffa59433" +checksum = "15ee168e30649f7f234c3d49ef5a7a6cbf5134289bc46c29ff3155fa3221c225" dependencies = [ "cfg-if", "indoc", @@ -913,9 +885,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.22.2" +version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e8730e591b14492a8945cdff32f089250b05f5accecf74aeddf9e8272ce1fa8" +checksum = "e61cef80755fe9e46bb8a0b8f20752ca7676dcc07a5277d8b7768c6172e529b3" dependencies = [ "once_cell", "python3-dll-a", @@ -924,9 +896,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.22.2" +version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e97e919d2df92eb88ca80a037969f44e5e70356559654962cbb3316d00300c6" +checksum = "67ce096073ec5405f5ee2b8b31f03a68e02aa10d5d4f565eca04acc41931fa1c" dependencies = [ "libc", "pyo3-build-config", @@ -934,43 +906,43 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.22.2" +version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb57983022ad41f9e683a599f2fd13c3664d7063a3ac5714cae4b7bee7d3f206" +checksum = "2440c6d12bc8f3ae39f1e775266fa5122fd0c8891ce7520fa6048e683ad3de28" dependencies = [ "proc-macro2", "pyo3-macros-backend", "quote", - "syn 2.0.59", + "syn 2.0.77", ] [[package]] name = "pyo3-macros-backend" -version = "0.22.2" +version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec480c0c51ddec81019531705acac51bcdbeae563557c982aa8263bb96880372" +checksum = "1be962f0e06da8f8465729ea2cb71a416d2257dff56cbe40a70d3e62a93ae5d1" dependencies = [ "heck", "proc-macro2", "pyo3-build-config", "quote", - "syn 2.0.59", + "syn 2.0.77", ] [[package]] name = "python3-dll-a" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5f07cd4412be8fa09a721d40007c483981bbe072cd6a21f2e83e04ec8f8343f" +checksum = "bd0b78171a90d808b319acfad166c4790d9e9759bbc14ac8273fe133673dd41b" dependencies = [ "cc", ] [[package]] name = "quote" -version = "1.0.36" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -1033,23 +1005,23 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.4.1" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" dependencies = [ "bitflags", ] [[package]] name = "regex" -version = "1.10.4" +version = "1.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.6", - "regex-syntax 0.8.3", + "regex-automata 0.4.7", + "regex-syntax 0.8.4", ] [[package]] @@ -1063,13 +1035,13 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.3", + "regex-syntax 0.8.4", ] [[package]] @@ -1080,15 +1052,15 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" [[package]] name = "rustc-demangle" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "rustc-hash" @@ -1098,9 +1070,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustc_version" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" dependencies = [ "semver", ] @@ -1125,28 +1097,28 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "semver" -version = "1.0.22" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.198" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.198" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.77", ] [[package]] @@ -1158,11 +1130,17 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "signal-hook-registry" -version = "1.4.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" dependencies = [ "libc", ] @@ -1184,12 +1162,12 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "socket2" -version = "0.5.6" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -1200,9 +1178,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "subtle" -version = "2.5.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" @@ -1217,9 +1195,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.59" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -1234,28 +1212,28 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "target-lexicon" -version = "0.12.14" +version = "0.12.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" [[package]] name = "thiserror" -version = "1.0.58" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.58" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.77", ] [[package]] @@ -1270,39 +1248,38 @@ dependencies = [ [[package]] name = "tokio" -version = "1.37.0" +version = "1.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" dependencies = [ "backtrace", "bytes", "libc", "mio", - "num_cpus", "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] name = "tokio-macros" -version = "2.2.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.77", ] [[package]] name = "tokio-util" -version = "0.7.10" +version = "0.7.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" dependencies = [ "bytes", "futures-core", @@ -1313,7 +1290,6 @@ dependencies = [ "pin-project-lite", "slab", "tokio", - "tracing", ] [[package]] @@ -1335,7 +1311,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.77", ] [[package]] @@ -1359,6 +1335,16 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "tracing-serde" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1" +dependencies = [ + "serde", + "tracing-core", +] + [[package]] name = "tracing-subscriber" version = "0.3.18" @@ -1385,9 +1371,9 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "unindent" @@ -1403,15 +1389,15 @@ checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "waker-fn" -version = "1.1.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3c4517f54858c779bbcbf228f4fca63d121bf85fbecb2dc578cdf4a39395690" +checksum = "317211a0dc0ceedd78fb2ca9a44aed3d7b9b26f81870d485c07122b4350673b7" [[package]] name = "wasi" @@ -1424,13 +1410,12 @@ name = "wecare" version = "0.1.0" dependencies = [ "caring", - "castaway", "curve25519-dalek", - "enum_dispatch", "ff", "fixed", "rand", "tokio", + "tracing", ] [[package]] @@ -1464,22 +1449,13 @@ dependencies = [ "windows-targets 0.48.5", ] -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -1499,18 +1475,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", + "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]] @@ -1521,9 +1497,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" @@ -1533,9 +1509,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" @@ -1545,15 +1521,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" @@ -1563,9 +1539,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" @@ -1575,9 +1551,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" @@ -1587,9 +1563,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" @@ -1599,9 +1575,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "wyz" @@ -1614,26 +1590,27 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.7.32" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ + "byteorder", "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.32" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.77", ] [[package]] name = "zeroize" -version = "1.7.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/pycare/Cargo.toml b/pycare/Cargo.toml index c93c2a4..03d9efb 100644 --- a/pycare/Cargo.toml +++ b/pycare/Cargo.toml @@ -10,4 +10,5 @@ crate-type = ["cdylib"] [dependencies] pyo3 = { version = "0.22", features = ["abi3-py37", "generate-import-lib", "extension-module"]} +tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } wecare = { path = "../wecare" } diff --git a/pycare/caring.pyi b/pycare/caring.pyi index 6edbfeb..535d97e 100644 --- a/pycare/caring.pyi +++ b/pycare/caring.pyi @@ -1,27 +1,97 @@ -# TODO: Add documentation - class Id: - ... + """ + Id of a party + """ + class Opened: - ... + """ + An opened value. + + Use the Engine to evaluate it + """ + class Computed: - def as_float(self) -> list[float]: ... - def as_integer(self) -> list[int]: ... + """ + A computed result, needs to be recast into a value. + + The size needs to be manually tracked, + in the case of a scalar the size will be 1, + + and for any vectors given it will be the corresponding size + """ + + + def as_float(self) -> list[float]: + """ + Cast as a float + """ + + + + def as_int(self) -> list[int]: + """ + Cast as an integer + """ + + class Expr: + """ + An expression of an MPC routine + + Note: + This allows mixing between different vector sizes and scalars, + it will however be a runtime error to add, subcract or multiply + different sized vectors. + """ + @staticmethod - def share(num: float | int | list[float] | list[int]) -> Expr: ... + def share(num: int | float | list[int] | list[float]) -> Expr: + """ Share a given value or vector + + Warning: + - Integer-mode only supports unsigned (non-negative) integers. + Negative integers will be converted to floats + - Floats will be converted to fixed point, and as such + multiplication is currently unsupported. + + Returns: + An expression for the given share + """ + @staticmethod - def recv(id: Id) -> Expr: ... + def recv(id: Id) -> Expr: + """ + Receive a share from another party + + Returns: + An expression for the given share + """ + @staticmethod - def symmetric_share(num: float | int | list[float] | list[int], id: Id, size: int) -> list[Expr]: ... + def symmetric_share(num: int | float | list[int] | list[float], id: Id, size: int) -> list[Expr]: + """ Secret-share (symmetrically, all-parties at-once) a given value or vector + + Warning: + - Integer-mode only supports unsigned (non-negative) integers. + Negative integers will be converted to floats + - Floats will be converted to fixed point, and as such + multiplication is currently unsupported. - def open(self) -> Opened: ... + Returns: + A list of expressions, ordered by Ids + """ + + def open(self) -> Opened: + """ Open the given value + + An opened value needs to be processed in the engine to compute it's result + """ def __add__(self, other: Expr) -> Expr: ... def __sub__(self, other: Expr) -> Expr: ... @@ -31,6 +101,16 @@ class Expr: def __imul__(self, other: Expr) -> None: ... class Engine: + """ Create a new Engine + + Args: + scheme: 'shamir-32' or 'shamir-25519' or 'spdz-32' or 'spdz-25519' or 'feldman-25519' + address: address to listen on + peers: peer addresses (party members) to connect to + multithreaded: use a multithreaded runtime + threshold: in case of a threshold scheme, use the given threshold + preprocessed: if using spdz, use the following preprocessed data file. + """ def __init__( self, scheme: str, @@ -38,81 +118,106 @@ class Engine: peers: list[str], multithreaded: bool = False, threshold: int | None = None, - preprocessed: str | None = None, + preprocessed_path: str | None = None, ) -> None: ... - def execute(self, script: Opened) -> Computed: ... + def execute(self, script: Opened) -> Computed: + """ + Execute the opened value to evaluate it. + This runs the nesscary protocols to output it. - def id(self) -> Id: ... + Errors: This might error if the underlying computation fails - def peers(self) -> list[Id]: ... + Returns: + The result of the computation + """ + + + def id(self) -> Id: + """ + Returns: + Your id in the network + """ + + def peers(self) -> list[Id]: + """ + List the party members in the network + + Returns: + a list of party id's for each member + """ + + +""" + Preprocess mult. triples and preshares + + :param num_of_shares: number of shares and triples + :param path_to_pre: path(s) to write the preprocessed material + :param scheme: scheme to share in ('spdz-25519'|'spdz-32') + + The paths parameter also implicitly defines the amount of parties + that there will preprocessed for, as each will get their own file. +""" +def preproc(num_shares: int, num_triplets: int, *paths_to_pre: str, scheme: str = "spdz-25519") -> None: ... # # Old stuff # class OldEngine: - """ - Performs a summation with the connected parties. - Returns the sum of all the numbers. - :param a: number to summate with - """ - def sum(self, a: float) -> float: ... + def sum(self, a: float) -> float: + """ + Performs a summation with the connected parties. + Returns the sum of all the numbers. + :param a: number to summate with + """ - """ - Performs a summation of a vector with the connected parties. - Returns the sum of all the vector (element-wise) of all the numbers. - :param a: vector to summate with. + def sum_many(self, a: list[float]) -> list[float]: + """ + Performs a summation of a vector with the connected parties. + Returns the sum of all the vector (element-wise) of all the numbers. + :param a: vector to summate with. - Note: that all parties must supply the same length! - """ - def sum_many(self, a: list[float]) -> list[float]: ... + Note: that all parties must supply the same length! + """ - """ - Takedown the MPC Engine, releasing the resources and dropping connections. - """ - def takedown(self) -> None: ... + def takedown(self) -> None: + """ + Takedown the MPC Engine, releasing the resources and dropping connections. + """ -""" - Setup a MPC Engine for adding numbers together using SPDZ - The engine will connect to the given addresses and listen - on the first socket address. - :path_to_pre: path to precomputed triples - :param my_addr: the address to listen on - :param others: the addresses to connect to -""" -def spdz(path_to_pre: str, my_addr: str, *others: str) -> Engine: ... +def spdz(path_to_pre: str, my_addr: str, *others: str) -> Engine: + """ + Setup a MPC Engine for adding numbers together using SPDZ + The engine will connect to the given addresses and listen + on the first socket address. + :path_to_pre: path to precomputed triples + :param my_addr: the address to listen on + :param others: the addresses to connect to + """ -""" - Setup a MPC Engine for adding numbers together using Shamir Secret Sharing. - The engine will connect to the given addresses and listen - on the first socket address. - :threshold: threshold to use - :param my_addr: the address to listen on - :param horsepower: the addresses to connect to -""" -def shamir(threshold: int, my_addr: str, *others: str) -> Engine: ... +def shamir(threshold: int, my_addr: str, *others: str) -> Engine: + """ + Setup a MPC Engine for adding numbers together using Shamir Secret Sharing. + The engine will connect to the given addresses and listen + on the first socket address. + :threshold: threshold to use + :param my_addr: the address to listen on + :param horsepower: the addresses to connect to + """ -""" - Setup a MPC Engine for adding numbers together using Feldman Verifiable Secret Sharing. - The engine will connect to the given addresses and listen - on the first socket address. - :threshold: threshold to use - :param my_addr: the address to listen on - :param horsepower: the addresses to connect to -""" -def feldman(threshold: int, my_addr: str, *others: str) -> Engine: ... +def feldman(threshold: int, my_addr: str, *others: str) -> Engine: + """ + Setup a MPC Engine for adding numbers together using Feldman Verifiable Secret Sharing. + The engine will connect to the given addresses and listen + on the first socket address. + :threshold: threshold to use + :param my_addr: the address to listen on + :param horsepower: the addresses to connect to + """ -""" - Setup a MPC Engine for adding numbers together. - The engine will connect to the given addresses and listen - on the first socket address. - :param my_addr: the address to listen on - :param horsepower: the addresses to connect to -""" -def preproc(num_of_shares: int, *paths_to_pre: str) -> None: ... diff --git a/pycare/examples/lasso1.py b/pycare/examples/lasso1.py index fbd6fca..ee9299b 100644 --- a/pycare/examples/lasso1.py +++ b/pycare/examples/lasso1.py @@ -20,7 +20,7 @@ # Processing (only for spdz) print("Preprocessing...") -caring.preproc(100000, "./ctx1.bin", "./ctx2.bin") +caring.preproc(100000, 0, "./ctx1.bin", "./ctx2.bin") print("Running...") diff --git a/pycare/examples/test1.py b/pycare/examples/test1.py index 5e76a2d..b71a299 100644 --- a/pycare/examples/test1.py +++ b/pycare/examples/test1.py @@ -4,7 +4,7 @@ # However for starters, and testing purposses ONLY we will allow party 1 to do it # and save it where both party one and party two can find it. -caring.preproc(12, "./context1.bin,./context2.bin") +caring.preproc(12, 0, "./context1.bin", "./context2.bin") # engine = caring.spdz("./context1.bin", "127.0.0.1:1234", "127.0.0.1:1235") engine = caring.shamir(2, "127.0.0.1:1234", "127.0.0.1:1235") diff --git a/pycare/examples/vm1.py b/pycare/examples/vm1.py index e9d9518..ebe8262 100644 --- a/pycare/examples/vm1.py +++ b/pycare/examples/vm1.py @@ -1,13 +1,21 @@ -from caring import Expr, Engine +from caring import Expr, Engine, preproc -engine = Engine(scheme="shamir-25519", address="localhost:1234", peers=["localhost:1235"], threshold=1) +preproc(12, 10, "./context1.bin", "./context2.bin") -[a, b] = Expr.symmetric_share(23, id=engine.id(), size=2) +engine = Engine( + scheme="spdz-25519", + address="localhost:1234", + peers=["localhost:1235"], + threshold=1, + preprocessed_path="./context1.bin" +) -c = a + b; +[a, b] = Expr.symmetric_share([23, 3], id=engine.id(), size=2) + +c = a * b; script = c.open() -res = engine.execute(script).as_float() +res = engine.execute(script).as_int() print(res) diff --git a/pycare/examples/vm2.py b/pycare/examples/vm2.py index 0d48653..153ab84 100644 --- a/pycare/examples/vm2.py +++ b/pycare/examples/vm2.py @@ -1,13 +1,19 @@ from caring import Expr, Engine -engine = Engine(scheme="shamir-25519", address="localhost:1235", peers=["localhost:1234"], threshold=1) +engine = Engine( + scheme="spdz-25519", + address="localhost:1235", + peers=["localhost:1234"], + threshold=1, + preprocessed_path="./context2.bin" +) -[a, b] = Expr.symmetric_share(7, id=engine.id(), size=2) +[a, b] = Expr.symmetric_share([7, 2], id=engine.id(), size=2) -c = a + b; +c = a * b; script = c.open() -res = engine.execute(script).as_float() +res = engine.execute(script).as_int() print(res) diff --git a/pycare/src/expr.rs b/pycare/src/expr.rs index ef1dd6a..8b5545f 100644 --- a/pycare/src/expr.rs +++ b/pycare/src/expr.rs @@ -11,25 +11,25 @@ pub struct Opened(pub(crate) vm::Opened); #[derive(Debug, Clone, Copy)] pub struct Id(pub(crate) vm::Id); +#[allow(non_snake_case, reason = "We are doing python")] #[pymethods] impl Expr { /// Construct a new share expression #[staticmethod] fn share(num: &Bound<'_, PyAny>) -> PyResult { - let res = if let Ok(num) = num.extract::() { - let num = vm::Number::Float(num); - vm::Expr::share(num) - } else if let Ok(num) = num.extract::() { - // TODO: Consider signedness + // TODO: Consider signed integers + let res = if let Ok(num) = num.extract::() { let num = vm::Number::Integer(num); vm::Expr::share(num) - } else if let Ok(num) = num.extract::>() { - let num: Vec<_> = num.into_iter().map(vm::Number::Float).collect(); - vm::Expr::share_vec(num) + } else if let Ok(num) = num.extract::() { + let num = vm::Number::Float(num); + vm::Expr::share(num) } else if let Ok(num) = num.extract::>() { - // TODO: Consider signedness let num: Vec<_> = num.into_iter().map(vm::Number::Integer).collect(); vm::Expr::share_vec(num) + } else if let Ok(num) = num.extract::>() { + let num: Vec<_> = num.into_iter().map(vm::Number::Float).collect(); + vm::Expr::share_vec(num) } else { return Err(PyTypeError::new_err("num is not a number")); }; @@ -38,20 +38,20 @@ impl Expr { #[staticmethod] fn symmetric_share(num: &Bound<'_, PyAny>, id: Id, size: usize) -> PyResult> { - let res = if let Ok(num) = num.extract::() { - let num = vm::Number::Float(num); - vm::Expr::symmetric_share(num) - } else if let Ok(num) = num.extract::() { - // TODO: Consider signedness + // TODO: Consider signed integers + let res = if let Ok(num) = num.extract::() { let num = vm::Number::Integer(num); vm::Expr::symmetric_share(num) - } else if let Ok(num) = num.extract::>() { - let num: Vec<_> = num.into_iter().map(vm::Number::Float).collect(); - vm::Expr::symmetric_share_vec(num) + } else if let Ok(num) = num.extract::() { + let num = vm::Number::Float(num); + vm::Expr::symmetric_share(num) } else if let Ok(num) = num.extract::>() { // TODO: Consider signedness let num: Vec<_> = num.into_iter().map(vm::Number::Integer).collect(); vm::Expr::symmetric_share_vec(num) + } else if let Ok(num) = num.extract::>() { + let num: Vec<_> = num.into_iter().map(vm::Number::Float).collect(); + vm::Expr::symmetric_share_vec(num) } else { return Err(PyTypeError::new_err("num is not a number")); }; diff --git a/pycare/src/lib.rs b/pycare/src/lib.rs index 33623da..de4ec26 100644 --- a/pycare/src/lib.rs +++ b/pycare/src/lib.rs @@ -66,14 +66,31 @@ fn feldman(threshold: u32, my_addr: &str, others: &Bound<'_, PyTuple>) -> PyResu /// Calculate and save the preprocessing #[pyfunction] -#[pyo3(signature = (number_of_shares, *paths_to_pre))] -fn preproc(number_of_shares: usize, paths_to_pre: &Bound<'_, PyTuple>) { +#[pyo3(signature = (num_shares, num_triplets, *paths_to_pre, scheme="spdz-25519"))] +fn preproc( + num_shares: usize, + num_triplets: usize, + paths_to_pre: &Bound<'_, PyTuple>, + scheme: &str, +) -> PyResult<()> { let mut files: Vec = paths_to_pre .iter() - .map(|x| x.extract::().unwrap()) - .map(|p| File::create(p).unwrap()) - .collect(); - do_preproc(&mut files, &[number_of_shares, number_of_shares], false); + .map(|x| { + x.extract::() + .and_then(|name| File::create(name).map_err(|e| e.into())) + }) + .collect::>()?; + + match scheme { + "spdz-25519" => do_preproc(&mut files, &[num_shares, num_shares], num_triplets, false), + "spdz-32" => do_preproc(&mut files, &[num_shares, num_shares], num_triplets, true), + _ => { + return Err(pyo3::exceptions::PyValueError::new_err(format!( + "Invalid scheme: '{scheme}'" + ))); + } + } + .map_err(|e| pyo3::exceptions::PyValueError::new_err(e.to_string())) } #[pymethods] @@ -98,6 +115,14 @@ impl OldEngine { /// A Python module implemented in Rust. #[pymodule] fn caring(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { + // TODO: enable this + // pyo3_log::init(); + + // TODO: disable this + use tracing_subscriber::EnvFilter; + let filter = EnvFilter::from_default_env(); + tracing_subscriber::fmt().with_env_filter(filter).init(); + m.add_function(wrap_pyfunction!(spdz, m)?)?; m.add_function(wrap_pyfunction!(shamir, m)?)?; m.add_function(wrap_pyfunction!(feldman, m)?)?; diff --git a/pycare/src/vm.rs b/pycare/src/vm.rs index 4b776a8..3818e4a 100644 --- a/pycare/src/vm.rs +++ b/pycare/src/vm.rs @@ -18,7 +18,7 @@ impl Computed { } /// Parse the computed result as an integer - fn as_integer(&self) -> Vec { + fn as_int(&self) -> Vec { self.0.clone().map(|s| s.to_u64()).to_vec() } } @@ -34,14 +34,14 @@ impl Engine { /// * `threshold`: (optional) threshold if using a threshold scheme /// * `preprocessed`: (optional) path to preprocessed material #[new] - #[pyo3(signature = (scheme, address, peers, multithreaded=false, threshold=None, preprocessed=None))] + #[pyo3(signature = (scheme, address, peers, multithreaded=false, threshold=None, preprocessed_path=None))] fn new( scheme: &str, address: &str, peers: &Bound<'_, PyList>, multithreaded: bool, threshold: Option, - preprocessed: Option<&str>, + preprocessed_path: Option<&str>, ) -> PyResult { let peers = peers.iter().map(|x| x.extract::().unwrap().clone()); @@ -61,7 +61,7 @@ impl Engine { .field(field); let builder = builder.threshold(threshold.unwrap_or_default()); - let builder = match preprocessed { + let builder = match preprocessed_path { Some(path) => { let file = std::fs::File::open(path)?; builder.preprocessed(file) @@ -75,21 +75,26 @@ impl Engine { builder.single_threaded_runtime() }; - let builder = builder.connect_blocking().unwrap(); - let engine = builder.build(); + let engine = builder + .connect_blocking() + .map_err(pyo3::exceptions::PyBrokenPipeError::new_err)? + .build() + .map_err(|e| pyo3::exceptions::PyValueError::new_err(e.to_string()))?; Ok(Self(Mutex::new(engine))) } /// Execute a script /// /// * `script`: list of expressions to evaluate - fn execute(&self, script: &Opened) -> Computed { + fn execute(&self, script: &Opened) -> PyResult { let res = { let mut engine = self.0.lock().expect("Lock poisoned"); let script: vm::Opened = script.0.clone(); - engine.execute(script) + engine + .execute(script) + .map_err(|e| pyo3::exceptions::PyValueError::new_err(e.to_string()))? }; - Computed(res) + Ok(Computed(res)) } /// Your own Id diff --git a/rust-toolchain b/rust-toolchain index bc20060..339ede4 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ # vim: ft=toml [toolchain] -channel = "nightly-2024-08-21" +channel = "nightly-2024-09-03" diff --git a/src/algebra/math.rs b/src/algebra/math.rs index 1c535c6..22678b3 100644 --- a/src/algebra/math.rs +++ b/src/algebra/math.rs @@ -16,7 +16,7 @@ // TODO: Consider smallvec or tinyvec // TODO: Make parallel version it's own type switch on them using cfg.. -use std::ops::{Add, AddAssign, Sub, SubAssign}; +use std::ops::{Add, AddAssign, MulAssign, Sub, SubAssign}; use ff::Field; @@ -27,7 +27,7 @@ use ff::Field; /// /// If the rayon feature is enabled the operations will be parallelized. #[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] -pub struct Vector(Box<[F]>); +pub struct Vector(pub(super) Box<[F]>); impl Vector { pub const fn from_boxed_slice(slice: Box<[F]>) -> Self { @@ -55,6 +55,37 @@ impl Vector { } } +impl Vector { + pub fn scalar_mul(&mut self, scalar: &B) + where + for<'b> A: MulAssign<&'b B>, + { + self.0.iter_mut().for_each(|a| *a *= scalar); + } +} + +pub trait RowMult { + fn row_wise_mult(&mut self, slice: &[T]); +} + +impl RowMult for Vector +where + for<'b> A: MulAssign<&'b B>, +{ + fn row_wise_mult(&mut self, slice: &[B]) { + self.0 + .iter_mut() + .zip(slice.iter()) + .for_each(|(a, b)| *a *= b); + } +} + +impl super::Length for Vector { + fn len(&self) -> usize { + self.0.len() + } +} + impl std::ops::Deref for Vector { type Target = [F]; @@ -63,6 +94,12 @@ impl std::ops::Deref for Vector { } } +impl std::ops::DerefMut for Vector { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + impl std::ops::Index for Vector { type Output = F; @@ -182,6 +219,17 @@ macro_rules! inherent { inherent!(Add, add, AddAssign, add_assign); inherent!(Sub, sub, SubAssign, sub_assign); +impl std::ops::Neg for Vector +where + F: std::ops::Neg, +{ + type Output = Self; + + fn neg(self) -> Self::Output { + self.into_iter().map(|x| -x).collect() + } +} + /// Generic implementation of row-wise mult-assign /// /// Vector =* B diff --git a/src/algebra/mod.rs b/src/algebra/mod.rs index 7be3bb3..2739cdc 100644 --- a/src/algebra/mod.rs +++ b/src/algebra/mod.rs @@ -2,4 +2,9 @@ pub mod element; pub mod field; pub mod math; pub mod poly; -mod rayon; +pub mod rayon; + +#[allow(clippy::len_without_is_empty)] +pub trait Length { + fn len(&self) -> usize; +} diff --git a/src/algebra/rayon.rs b/src/algebra/rayon.rs index c6fb876..c5ece82 100644 --- a/src/algebra/rayon.rs +++ b/src/algebra/rayon.rs @@ -2,8 +2,23 @@ use std::ops::{Add, AddAssign, Div, DivAssign, Sub, SubAssign}; use rayon::prelude::*; +use crate::algebra::math; + #[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] -struct Vector(Box<[F]>); +#[repr(transparent)] +pub struct Vector(math::Vector); + +impl From> for Vector { + fn from(value: math::Vector) -> Self { + Self(value) + } +} + +impl From> for math::Vector { + fn from(val: Vector) -> Self { + val.0 + } +} macro_rules! inherent { ($trait2:ident, $fun2:ident, $trait1:ident, $fun1:ident) => { @@ -13,6 +28,7 @@ macro_rules! inherent { { fn $fun1(&mut self, rhs: &Self) { self.0 + .0 .par_iter_mut() .zip(rhs.0.par_iter()) .for_each(|(a, b)| $trait1::$fun1(a, b)); @@ -71,8 +87,8 @@ inherent!(Sub, sub, SubAssign, sub_assign); inherent!(Div, div, DivAssign, div_assign); impl super::math::Vector { - fn parallelize(self) -> Vector { - Vector(self.into_boxed_slice()) + pub fn parallelize(self) -> Vector { + Vector(self) } } @@ -90,8 +106,8 @@ impl FromParallelIterator for Vector { where I: IntoParallelIterator, { - let boxed = par_iter.into_par_iter().collect(); - Self(boxed) + let boxed: Box<[_]> = par_iter.into_par_iter().collect(); + Self(math::Vector(boxed)) } } @@ -106,7 +122,7 @@ where { fn mul_assign(&mut self, rhs: &B) { let b = rhs; - self.0.par_iter_mut().for_each(|a| *a *= b); + self.0 .0.par_iter_mut().for_each(|a| *a *= b); } } @@ -127,8 +143,8 @@ where fn mul(self, rhs: B) -> Self::Output { let b = rhs; - let internal = self.0.par_iter().map(|a| a * &b).collect(); - Vector(internal) + let internal: Box<[_]> = self.0 .0.par_iter().map(|a| a * &b).collect(); + Vector(math::Vector(internal)) } } diff --git a/src/lib.rs b/src/lib.rs index 888fb78..d26d486 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,7 @@ #![allow(clippy::cast_possible_truncation)] #![feature(async_fn_traits)] #![feature(async_closure)] +#![feature(iterator_try_collect)] pub mod algebra; mod help; diff --git a/src/net/agency.rs b/src/net/agency.rs index 889465e..5c1a608 100644 --- a/src/net/agency.rs +++ b/src/net/agency.rs @@ -28,19 +28,19 @@ use futures::Future; use itertools::Itertools; pub trait Broadcast: Send { - type BroadcastError: Error + Send + 'static; - // type Error: Error + 'static; + type BroadcastError: Error + Send + Sync + 'static; - /// Broadcast a message to all other parties. + /// Broadcast a single message to all other parties. /// /// * `msg`: Message to send + /// /// Returns: an error if there were problems broadcasting the message. fn broadcast( &mut self, msg: &(impl serde::Serialize + Sync), ) -> impl std::future::Future> + Send; - /// Broadcast a message to all parties and await their messages + /// Broadcast a single message to all parties and await their messages /// Messages are ordered by their index. /// /// This function is symmetric, and as such it is expected that all other parties @@ -99,11 +99,11 @@ impl<'a, B: Broadcast> Broadcast for &'a mut B { } } -// TODO: Possible rename this trait as it's name is confusing. +/// Uni(que) cast to every party pub trait Unicast { type UnicastError: Error + Send + 'static; - /// Unicast messages to each party + /// Send a unique message to each party /// /// Messages are supposed to be in order, meaning message `i` /// will be send to party `i`, skipping your own index. @@ -116,7 +116,7 @@ pub trait Unicast { msgs: &[impl serde::Serialize + Send + Sync], ) -> impl std::future::Future> + Send; - /// Unicast a message to each party and await their messages + /// Send a unique message to each party and await their messages /// Messages are supposed to be in order, meaning message `i` /// will be send to party `i`. /// @@ -128,7 +128,7 @@ pub trait Unicast { where T: serde::Serialize + serde::de::DeserializeOwned + Send + Sync; - /// Receive a message for each party. + /// Receive a message from each party. /// /// Asymmetric, waiting /// diff --git a/src/net/connection.rs b/src/net/connection.rs index 2721a5f..7177daf 100644 --- a/src/net/connection.rs +++ b/src/net/connection.rs @@ -1,4 +1,5 @@ //! Module for doing arbitrary communication in 'some' medium. +//! //! This 'medium' can be anything that implements `AsyncRead`/`AsyncWrite`. //! There is built-in support for TCP and in-memory duplex-based connections. //! @@ -34,6 +35,7 @@ use tokio_util::{ bytes::{Bytes, BytesMut}, codec::{FramedRead, FramedWrite, LengthDelimitedCodec}, }; +use tracing::instrument; use crate::net::{ connection::latency::Delayed, Channel, ReceiverError, RecvBytes, SendBytes, SplitChannel, @@ -101,6 +103,7 @@ pub struct Receiving(FramedRead); impl SendBytes for Sending { type SendError = ConnectionError; + #[instrument(skip(self))] async fn send_bytes(&mut self, bytes: Bytes) -> Result<(), Self::SendError> { SinkExt::<_>::send(&mut self.0, bytes) .await @@ -111,6 +114,7 @@ impl SendBytes for Sending { impl RecvBytes for Receiving { type RecvError = ConnectionError; + #[instrument(skip(self))] async fn recv_bytes(&mut self) -> Result { self.0 .next() @@ -146,6 +150,7 @@ impl< { type SendError = ConnectionError; + #[instrument(skip(self))] fn send_bytes( &mut self, bytes: Bytes, @@ -160,6 +165,7 @@ impl< { type RecvError = ConnectionError; + #[instrument(skip(self))] fn recv_bytes( &mut self, ) -> impl std::future::Future> + Send { diff --git a/src/net/mod.rs b/src/net/mod.rs index 3e35454..e13019b 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -1,4 +1,4 @@ -use std::{error::Error, future::Future}; +use std::{error::Error, fmt::Display, future::Future}; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use thiserror::Error; @@ -102,9 +102,17 @@ impl<'a, C: SplitChannel> SplitChannel for &'a mut C { #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Serialize, Deserialize)] pub struct Id(pub usize); +impl Display for Id { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let i = self.0; + write!(f, "{i}") + } +} + /// Tune to a specific channel pub trait Tuneable { type TuningError: Error + Send + 'static; + type Channel: SplitChannel + Send; fn id(&self) -> Id; @@ -118,10 +126,13 @@ pub trait Tuneable { id: Id, msg: &T, ) -> impl Future> + Send; + + fn channels(&mut self) -> &mut [Self::Channel]; } -impl<'a, R: Tuneable + ?Sized> Tuneable for &'a mut R { - type TuningError = R::TuningError; +impl<'a, N: Tuneable + ?Sized> Tuneable for &'a mut N { + type TuningError = N::TuningError; + type Channel = N::Channel; fn id(&self) -> Id { (**self).id() @@ -141,6 +152,10 @@ impl<'a, R: Tuneable + ?Sized> Tuneable for &'a mut R { ) -> impl Future> + Send { (**self).send_to(id, msg) } + + fn channels(&mut self) -> &mut [Self::Channel] { + (**self).channels() + } } /// General communication with support for most network functionality. diff --git a/src/net/mux.rs b/src/net/mux.rs index da2ebdc..8c1c630 100644 --- a/src/net/mux.rs +++ b/src/net/mux.rs @@ -1,14 +1,15 @@ //! Multiplexing Connections and Networks //! -//! This moudle provides tools to multiplex channels/connections and networks +//! This module provides tools to multiplex channels/connections and networks //! in order to run multiple protocols concurrently. -// TODO: Add Multiplex trait with impls for Network and SplitChannel? - use std::error::Error; use std::sync::Arc; -use futures::future::try_join_all; +use futures_concurrency::prelude::*; +use tracing::{instrument, Instrument}; + +use futures::{future::try_join_all, TryFutureExt}; use num_traits::ToPrimitive; use thiserror::Error; use tokio::sync::{ @@ -19,7 +20,7 @@ use tokio_util::bytes::{Buf, BufMut, Bytes, BytesMut}; use crate::{ help, - net::{network::Network, Channel, RecvBytes, SendBytes, SplitChannel}, + net::{network::Network, Channel, Communicate, RecvBytes, SendBytes, SplitChannel, Tuneable}, }; #[derive(Debug, Error)] @@ -31,17 +32,33 @@ pub enum MuxError { } pub struct MuxedSender { - id: usize, + mux_id: usize, gateway: mpsc::UnboundedSender, error: oneshot::Receiver, } +impl std::fmt::Debug for MuxedSender { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("MuxedSender") + .field("mux_id", &self.mux_id) + .finish_non_exhaustive() + } +} + pub struct MuxedReceiver { - id: usize, + mux_id: usize, mailbox: mpsc::UnboundedReceiver, error: oneshot::Receiver, } +impl std::fmt::Debug for MuxedReceiver { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("MuxedReceiver") + .field("mux_id", &self.mux_id) + .finish_non_exhaustive() + } +} + struct MultiplexedMessage(Bytes, usize); impl MultiplexedMessage { @@ -63,13 +80,14 @@ impl MultiplexedMessage { impl SendBytes for MuxedSender { type SendError = MuxError; + #[instrument] async fn send_bytes(&mut self, bytes: tokio_util::bytes::Bytes) -> Result<(), Self::SendError> { if let Ok(err) = self.error.try_recv() { return Err(err); }; self.gateway - .send(MultiplexedMessage(bytes, self.id)) + .send(MultiplexedMessage(bytes, self.mux_id)) .map_err(|_| MuxError::DeadGateway) } } @@ -77,6 +95,7 @@ impl SendBytes for MuxedSender { impl RecvBytes for MuxedReceiver { type RecvError = MuxError; + #[instrument] async fn recv_bytes(&mut self) -> Result { tokio::select! { msg = self.mailbox.recv() => { @@ -100,6 +119,7 @@ impl RecvBytes for MuxedReceiver { /// Errors are propogated from the underlying connection inside the gateway. /// /// The gateway needs to be driven for the muxed connection to function using [`Gateway::drive`]. +#[derive(Debug)] pub struct MuxConn(MuxedSender, MuxedReceiver); impl Channel for MuxConn { @@ -135,6 +155,13 @@ impl SplitChannel for MuxConn { } } +impl MuxConn { + #[instrument] + pub async fn shutdown(mut self) { + let _ = (self.0.send(&()), self.1.recv::<()>()).join().await; + } +} + /// # Multiplexed Gateway Channel /// /// Enables splitting a channel into multiple multiplexed channels. @@ -161,7 +188,7 @@ impl SplitChannel for MuxConn { /// gateway.drive().await.unwrap(); /// }); /// -/// tokio::spawn( async {// party 2 +/// tokio::spawn(async {// party 2 /// let con = c2; /// let (mut gateway, mut m1) = Gateway::single(con); /// let mut m2 = gateway.muxify(); @@ -175,7 +202,7 @@ impl SplitChannel for MuxConn { /// }); /// gateway.drive().await.unwrap(); /// }); -/// }) +/// # }) /// ``` pub struct Gateway where @@ -188,12 +215,23 @@ where outbox: mpsc::WeakUnboundedSender, } +impl std::fmt::Debug for Gateway { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let n = self.mailboxes.len(); + f.debug_struct("Gateway") + .field("mailboxes", &n) + .finish_non_exhaustive() + } +} + #[derive(Debug, Error)] -pub enum GatewayError { - #[error("Multiplexed connection {0} disappered")] - MailboxNotFound(usize), +pub enum GatewayError { + #[error("Bad packet: {packet:?}")] + BadPacket { packet: BytesMut }, + #[error("Multiplexed connection not found {mux_id}")] + MailboxNotFound { mux_id: usize }, #[error("Underlying connection died: {0}")] - DeadConnection(#[from] Arc), + DeadConnection(#[from] Arc), } impl Gateway { @@ -202,13 +240,10 @@ impl Gateway { /// # Errors /// /// - [`GatewayError::MailboxNotFound`] if a given multiplexed connections has been - /// dropped and is receiving messages. + /// dropped and is receiving messages. /// - [`GatewayError::DeadConnection`] if the underlying connection have failed. /// - pub async fn drive(mut self) -> Result> { - // TODO: maybe have this be nonconsuming so it can be resumed after new muxes are added? - // This however would compromise the possible destruction when errors occur, - // thus leaving the error handling in a bad state. + pub async fn drive(mut self) -> Result { let (sending, recving) = self.channel.split(); let send_out = async { loop { @@ -226,16 +261,25 @@ impl Gateway { loop { match recving.recv_bytes().await { Ok(mut msg) => { - let id = msg.get_u32() as usize; + let addr = msg.get_u32(); let bytes = msg; - let Some(mailbox) = self.mailboxes.get_mut(id) else { - break Err(GatewayError::MailboxNotFound(id)); + if addr == 0xDEAD_BEEF { + break Ok(None); + }; + let Some(mailbox) = self.mailboxes.get_mut(addr as usize) else { + let mut msg = BytesMut::new(); + msg.put_u32(addr); // put number back; + msg.extend_from_slice(&bytes); + tracing::error!("Got bad packet: {msg:?}"); + break Err(GatewayError::BadPacket { packet: msg }); }; let Ok(()) = mailbox.send(bytes) else { - break Err(GatewayError::MailboxNotFound(id)); + let addr = addr as usize; + tracing::error!("Multiplexed connection not found: {addr}"); + break Err(GatewayError::MailboxNotFound { mux_id: addr }); }; } - Err(e) => break Ok(e), + Err(e) => break Ok(Some(e)), } } }; @@ -244,25 +288,39 @@ impl Gateway { res = send_out => { match res { Ok(()) => { + let mut signal = BytesMut::new(); + signal.put_u32(0xDEAD_BEEF); + let signal = signal.freeze(); + let (sending, recving) = self.channel.split(); + let _ = (sending.send_bytes(signal), recving.recv_bytes()).try_join().await; Ok(self) }, Err(err) => { + tracing::error!("Failed to send message: {err}"); Err(self.propogate_error(err)) } } }, - err = recv_in => { - let err : C::Error = err?; // return early on missing mailbox. - println!("Got an error! {err:?}"); - Err(self.propogate_error(err)) + res = recv_in => { + let ok = res?; + match ok { + None => { + let mut signal = BytesMut::new(); + signal.put_u32(0xDEAD_BEEF); + let signal = signal.freeze(); + let _ = self.channel.send_bytes(signal).await; + Ok(self) + }, + Some(e) => Err(self.propogate_error(e)), + } }, } } - fn propogate_error(mut self, err: E) -> GatewayError { + fn propogate_error(mut self, err: E) -> GatewayError { let err = Arc::new(err); for [c1, c2] in self.errors.drain(..) { - // ignore dropped connections, + // Ignore dropped connections, // they can't handle errors when they don't exist. let _ = c1.send(MuxError::Connection(err.clone())); let _ = c2.send(MuxError::Connection(err.clone())); @@ -272,7 +330,7 @@ impl Gateway { fn new(channel: C) -> (Self, UnboundedSender) { let (outbox, inbox) = unbounded_channel(); - let link = outbox.clone(); // needs to kept alive + let link = outbox.clone(); // Needs to kept alive let outbox = outbox.downgrade(); let gateway = Self { channel, @@ -305,6 +363,7 @@ impl Gateway { /// Returns a gateway which the [`MuxConn`] communicate through, along with the [`MuxConn`]'s #[must_use] pub fn multiplex(con: C, n: usize) -> (Self, Vec) { + tracing::debug!("Multiplexing Connnection into {n}"); let (mut gateway, link) = Self::new(con); let muxes: Vec<_> = (0..n).map(|_| gateway.add_mux(link.clone())).collect(); (gateway, muxes) @@ -325,10 +384,18 @@ impl Gateway { fn add_mux(&mut self, gateway: UnboundedSender) -> MuxConn { let id = self.mailboxes.len(); let (errors_coms1, error) = oneshot::channel(); - let sender = MuxedSender { id, gateway, error }; + let sender = MuxedSender { + mux_id: id, + gateway, + error, + }; let (outbox, mailbox) = tokio::sync::mpsc::unbounded_channel(); let (errors_coms2, error) = oneshot::channel(); - let receiver = MuxedReceiver { id, mailbox, error }; + let receiver = MuxedReceiver { + mux_id: id, + mailbox, + error, + }; self.errors.push([errors_coms1, errors_coms2]); self.mailboxes.push(outbox); MuxConn(sender, receiver) @@ -346,34 +413,77 @@ impl Gateway { } pub struct ActiveGateway( - tokio::task::JoinHandle, GatewayError>>, + tokio::task::JoinHandle, GatewayError>>, ); impl Gateway { + /// Run a gateway on a tokio task. pub fn go(self) -> ActiveGateway { ActiveGateway(tokio::spawn(self.drive())) } } impl ActiveGateway { - pub async fn deactivate(self) -> Result, GatewayError> { + pub async fn deactivate(self) -> Result, GatewayError> { self.0.await.unwrap() } } +/// Collection of [Gateway]s for an entire network. +/// +/// Needs to be driven in order to operate the multiplexed networks. +/// Either using [NetworkGateway::drive] or [NetworkGateway::go] +/// pub struct NetworkGateway { gateways: Vec>, index: usize, } -type MuxNet = Network; +impl NetworkGateway { + /// Run a gateway on a tokio task. + pub fn go(self) -> ActiveNetworkGateway { + ActiveNetworkGateway(tokio::spawn(self.drive())) + } +} +pub struct ActiveNetworkGateway( + tokio::task::JoinHandle, NetworkGatewayError>>, +); +impl ActiveNetworkGateway { + pub async fn deactivate(self) -> Result, NetworkGatewayError> { + self.0.await.unwrap() + } +} + +/// A Network consisting of multiplexed connections, +/// linked to a [NetworkGateway] +pub type MultiplexedNetwork = Network; + +impl MultiplexedNetwork { + #[instrument] + pub async fn shutdown(self) { + let _: Vec<_> = self + .connections + .into_co_stream() + .map(|con| con.shutdown()) + .collect() + .await; + } +} + +#[derive(Debug, Error)] +#[error("Gateway {id} crashed: {reason}")] +pub struct NetworkGatewayError { + pub id: usize, + reason: GatewayError, +} impl NetworkGateway where C: SplitChannel + Send, { #[must_use] - pub fn multiplex(net: Network, n: usize) -> (NetworkGateway, Vec) { + pub fn multiplex(net: Network, n: usize) -> (NetworkGateway, Vec) { + tracing::debug!("Multiplexing Network into {n}"); let mut gateways = Vec::new(); let mut matrix = Vec::new(); let index = net.index; @@ -387,22 +497,41 @@ where let matrix = help::transpose(matrix); let muxnets: Vec<_> = matrix .into_iter() - .map(|connections| MuxNet { connections, index }) + .map(|connections| MultiplexedNetwork { connections, index }) .collect(); + tracing::debug!("Network successfully multiplexed"); (gateway, muxnets) } pub fn multiplex_borrow( net: &mut Network, n: usize, - ) -> (NetworkGateway<&mut C>, Vec) { + ) -> (NetworkGateway<&mut C>, Vec) { let net = net.as_mut(); NetworkGateway::<&mut C>::multiplex(net, n) } - pub async fn drive(self) -> Result> { - let gateways = try_join_all(self.gateways.into_iter().map(Gateway::drive)).await?; + pub fn multiplexify<'tun, T>( + tuneable: &'tun mut T, + n: usize, + ) -> (NetworkGateway<&'tun mut C>, Vec>) + where + T: Tuneable, + { + let index = tuneable.id().0; + let channels: &'tun mut [C] = tuneable.channels(); + let connections: Vec<&'tun mut C> = channels.iter_mut().collect(); + let network = Network { connections, index }; + NetworkGateway::<&'tun mut C>::multiplex(network, n) + } + + pub async fn drive(self) -> Result { + let connections = self.gateways.len(); + let gateways = try_join_all(self.gateways.into_iter().map(Gateway::drive)) + .instrument(tracing::debug_span!("Driving gateway", connections)) + .map_err(|reason| NetworkGatewayError { reason, id: 0 }) + .await?; Ok(Self { gateways, index: self.index, @@ -416,15 +545,27 @@ where Network { connections, index } } - pub fn new_mux(&mut self) -> MuxNet { + pub fn new_mux(&mut self) -> MultiplexedNetwork { let connections = self.gateways.iter_mut().map(Gateway::muxify).collect(); - MuxNet { + MultiplexedNetwork { connections, index: self.index, } } } +pub struct MultiplexGroup { + gateway: NetworkGateway, + muxes: Vec, +} + +impl MultiplexGroup { + pub async fn stream(self) -> impl ConcurrentStream { + self.gateway.go(); + self.muxes.into_co_stream() + } +} + #[cfg(test)] mod test { use std::time::Duration; @@ -432,6 +573,7 @@ mod test { use futures_concurrency::future::Join; use itertools::Itertools; use tokio::join; + use tracing::Instrument; use crate::net::{ connection::Connection, @@ -450,7 +592,7 @@ mod test { } #[tokio::test] - async fn sunshine() { + async fn connection_works() { let (c1, c2) = Connection::in_memory(); let p1 = async { let (gateway, mut muxes) = Gateway::multiplex(c1, 3); @@ -465,12 +607,13 @@ mod test { s1 + &s2 + &s3 }; - let (s, gateway) = join!(s, gateway.drive()); + let (s, gateway) = (s, gateway.drive()).join().await; let mut gateway = gateway.unwrap(); gateway.channel.send(&"bye".to_owned()).await.unwrap(); gateway.channel.shutdown().await.unwrap(); s - }; + } + .instrument(tracing::info_span!("Player-0")); let p2 = async { let (gateway, mut muxes) = Gateway::multiplex(c2, 3); @@ -488,7 +631,8 @@ mod test { let _: String = gateway.channel.recv().await.unwrap(); gateway.channel.shutdown().await.unwrap(); s - }; + } + .instrument(tracing::info_span!("Player-1")); let (s1, s2) = futures::join!(p1, p2); assert_eq!(s1, "Hello, how are you? Great!"); @@ -496,7 +640,7 @@ mod test { } #[tokio::test] - async fn moonshine() { + async fn connection_handles_errors() { let (c1, c2) = Connection::in_memory(); let p1 = async { let (gateway, mut muxes) = Gateway::multiplex(c1, 3); @@ -574,4 +718,33 @@ mod test { .await .unwrap(); } + + #[tokio::test] + async fn network_borrowed_no_tasks() { + let res = crate::testing::Cluster::new(3) + .run(|mut net| async move { + let net_ref = net.as_mut(); + let (gateway, mut muxed) = NetworkGateway::multiplex(net_ref, 2); + let (m1, m2) = muxed.drain(..).collect_tuple().unwrap(); + let h1 = async move { + let mut m = m1; + let res = m.symmetric_broadcast(String::from("Hello")).await.unwrap(); + assert_eq!(res, vec!["Hello"; 3]); + true + }; + let h2 = async move { + let mut m = m2; + let res = m.symmetric_broadcast(String::from("World")).await.unwrap(); + assert_eq!(res, vec!["World"; 3]); + true + }; + let (r1, r2, _) = futures::join!(h1, h2, gateway.drive()); + net.shutdown().await.unwrap(); + r1 && r2 + }) + .await + .unwrap(); + + assert!(res.into_iter().all(|x| x)); + } } diff --git a/src/net/network.rs b/src/net/network.rs index d974ebb..f12f699 100644 --- a/src/net/network.rs +++ b/src/net/network.rs @@ -5,6 +5,7 @@ use futures::future::join_all; use futures::prelude::*; use itertools::Itertools; use rand::{thread_rng, Rng}; +use tokio::time::error::Elapsed; use tokio_util::bytes::Bytes; use crate::net::{ @@ -33,7 +34,6 @@ use crate::net::{ /// /// * `connections`: Connections, one for each peer, sorted by their index, skipping our own index. /// * `index`: My own index -#[derive(Debug)] pub struct Network { // NOTE: // We could also insert a 'fake' Connection into the set for the representation of ourselves. @@ -42,11 +42,24 @@ pub struct Network { pub(crate) index: usize, } +impl std::fmt::Debug for Network { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let n = self.connections.len(); + f.debug_struct("Network") + .field("connections", &n) + .field("index", &self.index) + .finish() + } +} + #[derive(thiserror::Error, Debug)] -#[error("Error communicating with {id}: {source}")] pub enum NetworkError { + #[error("Error receiving from {id}: {source}")] Incoming { id: u32, source: ReceiverError }, + #[error("Error sending to {id}: {source}")] Outgoing { id: u32, source: U }, + #[error("{id} timeouted after {elapsed:?}")] + TimeOut { id: u32, elapsed: Elapsed }, } #[allow(type_alias_bounds)] // It clearly matters, stop complaining @@ -54,7 +67,7 @@ type NetResult = std::result::Result Network { - pub(crate) fn id_to_index(&self, Id(id): Id) -> usize { + fn id_to_index(&self, Id(id): Id) -> usize { let n = self.connections.len() + 1; if id < self.index { id @@ -73,6 +86,11 @@ impl Network { Id(self.index) } + pub fn set_id(&mut self, id: Id) { + tracing::info!("Obtained new id = {id:?}"); + self.index = id.0; + } + pub fn prev_neighbour(&self) -> Id { let n = self.connections.len(); Id((self.index + n - 1) % n) @@ -85,10 +103,7 @@ impl Network { pub fn peers(&self) -> Vec { let n = self.connections.len(); - (0..=n) - .map(|i| Id(i)) - .filter(|id| *id != self.id()) - .collect_vec() + (0..=n).map(Id).filter(|id| *id != self.id()).collect_vec() } /// Returns a range for representing the participants. @@ -277,13 +292,7 @@ impl Network { .into_iter() .map(|(id, m)| match m { Ok(m) => m.map_err(|e| NetworkError::Incoming { id, source: e }), - Err(_duration) => { - todo!("handle it") - // Err(NetworkError { - // id, - // source: ConnectionError::TimeOut(duration), - //}) - } + Err(elapsed) => Err(NetworkError::TimeOut { id, elapsed }), }) .collect::>()?; @@ -314,7 +323,10 @@ impl Network { connections.insert(0, None); // Remove our own position, remember we are at zero. - let (i, _) = results.iter().find_position(|&i| *i == 0).unwrap(); + let (i, _) = results + .iter() + .find_position(|&i| *i == 0) + .expect("Id zero should be in there"); results.remove(i); // remember we have removed it to not remove it twice. self.index = i; @@ -324,6 +336,9 @@ impl Network { }); // Add it back. self.connections.extend(sorted); + + let id = self.id(); + tracing::info!("Obtained new id = {id:?} from id-resolution"); Ok(()) } @@ -372,7 +387,7 @@ impl Network { impl Unicast for Network { type UnicastError = NetworkError; - #[tracing::instrument(skip_all)] + #[tracing::instrument(level = "trace", skip(msgs))] async fn unicast( &mut self, msgs: &[impl serde::Serialize + Sync], @@ -380,7 +395,7 @@ impl Unicast for Network { self.unicast(msgs).await } - #[tracing::instrument(skip_all)] + #[tracing::instrument(level = "debug", skip(msgs))] async fn symmetric_unicast(&mut self, msgs: Vec) -> Result, Self::UnicastError> where T: serde::Serialize + serde::de::DeserializeOwned + Sync, @@ -388,7 +403,7 @@ impl Unicast for Network { self.symmetric_unicast(msgs).await } - #[tracing::instrument(skip_all)] + #[tracing::instrument(level = "trace")] async fn receive_all( &mut self, ) -> Result, Self::UnicastError> { @@ -403,7 +418,7 @@ impl Unicast for Network { impl Broadcast for Network { type BroadcastError = NetworkError; - #[tracing::instrument(skip_all)] + #[tracing::instrument(level = "trace", skip(msg))] async fn broadcast( &mut self, msg: &(impl serde::Serialize + Sync), @@ -411,7 +426,7 @@ impl Broadcast for Network { self.broadcast(msg).await } - #[tracing::instrument(skip_all)] + #[tracing::instrument(level = "trace", skip(msg))] async fn symmetric_broadcast(&mut self, msg: T) -> Result, Self::BroadcastError> where T: serde::Serialize + serde::de::DeserializeOwned + Sync, @@ -419,6 +434,7 @@ impl Broadcast for Network { self.symmetric_broadcast(msg).await } + #[tracing::instrument(level = "trace")] fn recv_from( &mut self, id: Id, @@ -438,6 +454,7 @@ impl Tuneable for Network { self.id() } + #[tracing::instrument(level = "trace")] async fn recv_from( &mut self, id: Id, @@ -452,6 +469,7 @@ impl Tuneable for Network { }) } + #[tracing::instrument(level = "trace", skip(msg))] async fn send_to( &mut self, id: Id, @@ -466,6 +484,11 @@ impl Tuneable for Network { source: e, }) } + + type Channel = C; + fn channels(&mut self) -> &mut [C] { + &mut self.connections + } } impl Communicate for Network {} @@ -512,6 +535,7 @@ impl InMemoryNetwork { networks } + #[tracing::instrument(level = "trace")] pub async fn shutdown(self) -> Result<(), std::io::Error> { let futs = self .connections @@ -555,6 +579,7 @@ impl TcpNetwork { /// /// * `me`: Socket address to open to /// * `peers`: Socket addresses of other peers + #[tracing::instrument] pub async fn connect(me: SocketAddr, peers: &[SocketAddr]) -> NetResult { let n = peers.len(); @@ -603,6 +628,7 @@ impl TcpNetwork { Ok(network) } + #[tracing::instrument] pub async fn shutdown(self) -> Result<(), std::io::Error> { let futs = self .connections diff --git a/src/protocols/beaver.rs b/src/protocols/beaver.rs index 672783e..dec7b52 100644 --- a/src/protocols/beaver.rs +++ b/src/protocols/beaver.rs @@ -2,18 +2,19 @@ use std::iter; use itertools::{izip, multiunzip}; use rand::RngCore; +use serde::{Deserialize, Serialize}; use crate::{ - algebra::field::Field, + algebra::{field::Field, math::RowMult}, net::{agency::Broadcast, Communicate}, schemes::{ interactive::{InteractiveShared, InteractiveSharedMany}, - Shared, + Shared, SharedMany, }, }; /// Beaver (Multiplication) Triple -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct BeaverTriple { pub shares: (S, S, S), } @@ -81,6 +82,51 @@ impl> BeaverTriple { } } +impl BeaverTriple +where + S: InteractiveSharedMany, +{ + pub fn vectorized(vector: impl Iterator) -> BeaverTriple { + use itertools::MultiUnzip; + let (a, b, c): (Vec<_>, Vec<_>, Vec<_>) = + vector.map(|BeaverTriple { shares }| shares).multiunzip(); + let a = a.into_iter().collect(); + let b = b.into_iter().collect(); + let c = c.into_iter().collect(); + let shares = (a, b, c); + BeaverTriple { shares } + } +} + +impl BeaverTriple +where + S: SharedMany, + F: Field, +{ + pub fn fake_vec( + ctx: &S::Context, + vector_size: usize, + mut rng: impl RngCore, + ) -> Vec> { + use itertools::MultiUnzip; + let (a, b, c): (Vec<_>, Vec<_>, Vec<_>) = (0..vector_size) + .map(|_| { + let a = F::random(&mut rng); + let b = F::random(&mut rng); + (a, b, a * b) + }) + .multiunzip(); + + // Share (preproccess) + let a = S::share_many(ctx, &a, &mut rng); + let b = S::share_many(ctx, &b, &mut rng); + let c = S::share_many(ctx, &c, &mut rng); + itertools::izip!(a, b, c) + .map(|(a, b, c)| BeaverTriple { shares: (a, b, c) }) + .collect() + } +} + /// Perform multiplication using beaver triples /// /// * `ctx`: context for secret sharing scheme @@ -139,17 +185,31 @@ pub async fn beaver_multiply_many< } pub async fn beaver_multiply_vector< - C, F: Field, S: InteractiveSharedMany + std::ops::Mul, >( - _ctx: &mut S::Context, - _x: S::VectorShare, - _y: S::VectorShare, - _triples: &[BeaverTriple], - _coms: impl Communicate, -) { - todo!() + ctx: &mut S::Context, + x: &S::VectorShare, + y: &S::VectorShare, + triple: BeaverTriple, // TODO: Convert between this and a Vec + mut coms: impl Communicate, +) -> Result { + let BeaverTriple { shares: (a, b, c) } = triple; + + let ax = x.clone() + &a; + let by = y.clone() + &b; + + let ax = S::recombine_many(ctx, ax, &mut coms).await?; + let by = S::recombine_many(ctx, by, &mut coms).await?; + + let mut yax = y.clone(); + yax.row_wise_mult(&ax); + + let mut aby = a; + aby.row_wise_mult(&(-by)); + + let z = yax + &aby + &c; + Ok(z) } #[derive(Clone)] diff --git a/src/schemes/feldman.rs b/src/schemes/feldman.rs index 43f3e70..904ab76 100644 --- a/src/schemes/feldman.rs +++ b/src/schemes/feldman.rs @@ -1,5 +1,6 @@ //! This is an implementation of verifiable secret sharing using Feldman's scheme -//! see +//! +//! See //! or //! //! The scheme can be instansiated with any field F and a corresponding group G @@ -19,11 +20,11 @@ use std::{ }; use crate::{ - algebra::math::Vector, + algebra::math::{RowMult, Vector}, net::agency::Unicast, schemes::{ shamir::{self}, - SharedMany, + Length, SharedMany, }, }; use crate::{algebra::poly::Polynomial, schemes::shamir::ShamirParams}; @@ -232,6 +233,29 @@ pub struct VecVerifiableShare { polys: Box<[Polynomial]>, } +impl RowMult for VecVerifiableShare +where + G: for<'a> MulAssign<&'a F>, +{ + fn row_wise_mult(&mut self, slice: &[F]) { + self.shares + .ys + .iter_mut() + .zip(slice.iter()) + .for_each(|(a, b)| *a = *b); + self.polys + .iter_mut() + .zip(slice.iter()) + .for_each(|(poly, b)| poly.0 *= b); + } +} + +impl Length for VecVerifiableShare { + fn len(&self) -> usize { + self.shares.len() + } +} + impl SharedMany for VerifiableShare where F: Field + serde::Serialize + serde::de::DeserializeOwned, @@ -549,51 +573,4 @@ mod test { arr[3] = num[3]; Scalar::from_bytes_mod_order(arr) } - - #[test] - fn addition_fixpoint() { - const PARTIES: std::ops::Range = 1..5u32; - let a = 1.0; - let b = 3.0; - type Fix = fixed::FixedU32<16>; - // Function to pad a u32 to a [u8; 32] - - let a = Fix::from_num(a); - let b = Fix::from_num(b); - let v1 = to_scalar(a.to_bits()); - let v2 = to_scalar(b.to_bits()); - v2.invert(); - - let mut rng = thread_rng(); - let parties: Vec<_> = PARTIES.map(Scalar::from).collect(); - let ctx = ShamirParams { - threshold: 2, - ids: parties, - }; - let shares1 = share::(v1, &ctx.ids, 2, &mut rng); - let shares2 = share::(v2, &ctx.ids, 2, &mut rng); - - for (share, x) in shares1.iter().zip(ctx.ids.iter()) { - assert!(share.verify(*x)); - } - for (share, x) in shares2.iter().zip(ctx.ids.iter()) { - assert!(share.verify(*x)); - } - - let shares: Vec<_> = shares1 - .into_iter() - .zip(shares2) - .map(|(s1, s2)| s1 + s2) - .collect(); - - for (share, x) in shares.iter().zip(ctx.ids.iter()) { - assert!(share.verify(*x)); - } - - let vsum = reconstruct(&ctx, &shares).unwrap(); - let sum = &vsum.as_bytes()[0..4]; - let sum: [u8; 4] = sum.try_into().unwrap(); - let sum = Fix::from_le_bytes(sum); - assert_eq!(a + b, sum); - } } diff --git a/src/schemes/mod.rs b/src/schemes/mod.rs index 2b798f0..da3b5d5 100644 --- a/src/schemes/mod.rs +++ b/src/schemes/mod.rs @@ -33,7 +33,13 @@ use std::{ use rand::RngCore; -use crate::{algebra::math::Vector, net::Communicate}; +use crate::{ + algebra::{ + math::{RowMult, Vector}, + Length, + }, + net::Communicate, +}; /// Currently unused trait, but might be a better way to represent that a share /// can be multiplied by a const, however, it could also just be baked into 'Shared' directly. @@ -123,7 +129,9 @@ pub trait SharedMany: Shared { type Vectorized: Sized + FromIterator + for<'a> Add<&'a Self::Vectorized, Output = Self::Vectorized> - + for<'b> Sub<&'b Self::Vectorized, Output = Self::Vectorized> + + for<'a> Sub<&'a Self::Vectorized, Output = Self::Vectorized> + + RowMult + + Length + serde::Serialize + serde::de::DeserializeOwned + Clone @@ -157,6 +165,7 @@ pub mod interactive { use std::ops::Mul; use thiserror::Error; + use tracing::instrument; use crate::{ algebra::math::Vector, @@ -287,7 +296,9 @@ pub mod interactive { type VectorShare: Sized + FromIterator + for<'a> Add<&'a Self::VectorShare, Output = Self::VectorShare> - + for<'b> Sub<&'b Self::VectorShare, Output = Self::VectorShare> + + for<'a> Sub<&'a Self::VectorShare, Output = Self::VectorShare> + + RowMult + + Length + serde::Serialize + serde::de::DeserializeOwned + Clone @@ -331,6 +342,7 @@ pub mod interactive { { type VectorShare = S::Vectorized; + #[instrument(skip_all)] async fn share_many( ctx: &mut Self::Context, secrets: &[Self::Value], @@ -345,6 +357,7 @@ pub mod interactive { Ok(my_share) } + #[instrument(skip_all)] async fn symmetric_share_many( ctx: &mut Self::Context, secrets: &[Self::Value], @@ -359,6 +372,7 @@ pub mod interactive { Ok(shared) } + #[instrument(skip_all)] async fn receive_share_many( _ctx: &mut Self::Context, mut coms: impl Communicate, @@ -369,6 +383,7 @@ pub mod interactive { Ok(s) } + #[instrument(skip_all)] async fn recombine_many( ctx: &mut Self::Context, secrets: Self::VectorShare, @@ -408,6 +423,17 @@ pub mod interactive { } } +/// Reserve part of a context for performing +/// concurrent operations in the new subcontext. +pub trait Reserve { + /// Reserve `amount` operations in resources. + fn reserve(&mut self, amount: usize) -> Self; + + /// Put back unused resources. + fn put_back(&mut self, other: Self); +} + +// NOTE: Unused. pub trait Verify: Sized { type Args: Send; diff --git a/src/schemes/shamir.rs b/src/schemes/shamir.rs index f634129..bd47373 100644 --- a/src/schemes/shamir.rs +++ b/src/schemes/shamir.rs @@ -8,15 +8,16 @@ use serde::{de::DeserializeOwned, Serialize}; // TODO: Important! Switch RngCore to CryptoRngCore use crate::{ - algebra::math::{lagrange_coefficients, Vector}, + algebra::math::{lagrange_coefficients, RowMult, Vector}, net::agency::Unicast, - schemes::{interactive::InteractiveMult, SharedMany}, + schemes::{interactive::InteractiveMult, Length, Reserve, SharedMany}, }; use crate::algebra::poly::Polynomial; use derive_more::{Add, AddAssign, Sub, SubAssign}; /// A Shamir Secret Share +/// /// This is a point evaluated at `x` given a secret polynomial. /// Reconstruction can be done by obtaining `t` shares. /// Shares with the same `x` can be added together. @@ -37,6 +38,14 @@ pub struct ShamirParams { pub ids: Vec, } +impl Reserve for ShamirParams { + fn reserve(&mut self, _amount: usize) -> Self { + self.clone() + } + + fn put_back(&mut self, _other: Self) {} +} + // TODO: Collapse Field with Ser-De since we always require that combo? impl super::Shared for Share { type Context = ShamirParams; @@ -310,6 +319,18 @@ pub struct VecShare { pub(crate) ys: Vector, } +impl RowMult for VecShare { + fn row_wise_mult(&mut self, slice: &[F]) { + self.ys.row_wise_mult(slice); + } +} + +impl Length for VecShare { + fn len(&self) -> usize { + self.ys.len() + } +} + impl FromIterator> for VecShare { fn from_iter>>(iter: T) -> Self { let ys = iter.into_iter().map(|s| s.y).collect(); @@ -519,6 +540,7 @@ pub fn reconstruct_many( #[cfg(test)] mod test { use crate::algebra::element::Element32; + use rand::Rng; use super::*; @@ -590,47 +612,6 @@ mod test { assert_eq!(v, a.iter().zip(b).map(|(a, b)| a + b).collect::>()); } - use fixed::FixedU32; - use rand::Rng; - - #[test] - fn addition_fixpoint() { - // We test that we can secret-share a two *fixed point* numbers and add them. - let mut rng = rand::rngs::mock::StepRng::new(0, 7); - const PARTIES: std::ops::Range = 1..5u32; - type Fix = FixedU32<16>; - let a = 1.0; - let b = 3.0; - let a = Fix::from_num(a); - let b = Fix::from_num(b); - let ids: Vec<_> = PARTIES.map(Element32::from).collect(); - let ctx = ShamirParams { - threshold: 2, - ids: ids.clone(), - }; - - let vs1 = { - let v = Element32::from(a.to_bits() as u64); - dbg!(&v); - share(v, &ids, 4, &mut rng) - }; - let vs2 = { - let v = Element32::from(b.to_bits() as u64); - dbg!(&v); - share(v, &ids, 4, &mut rng) - }; - - // MPC - let shares: Vec<_> = vs1.iter().zip(vs2.iter()).map(|(&a, &b)| a + b).collect(); - let v = reconstruct(&ctx, &shares); - dbg!(v); - - // back to fixed - let v: u32 = v.into(); - let v = Fix::from_bits(v); - assert_eq!(v, a + b); - } - #[tokio::test] async fn multiplication() { let cluster = crate::testing::Cluster::new(5); diff --git a/src/schemes/spdz/mod.rs b/src/schemes/spdz/mod.rs index 76d98e6..ef28ae9 100644 --- a/src/schemes/spdz/mod.rs +++ b/src/schemes/spdz/mod.rs @@ -1,17 +1,17 @@ -// -//! This SPDZ implementation is primarely based on the following lecture by Ivan DamgÃ¥rd: +//! Implementation of SPDZ +//! +//! This implementation is primarely based on the following lecture by Ivan DamgÃ¥rd: //! (part one:) (and part two:) //! //! We will need some homomorphic encryption or oblivious transfer to enable preprocessing. //! But for now that is handled by a dealer. //! -// TODO: make costum errors. use crate::{ algebra::math::Vector, - net::{agency::Broadcast, Id}, + net::{agency::Broadcast, mux, Id}, protocols::commitments::{commit, verify_commit}, - schemes::interactive::InteractiveSharedMany, + schemes::{interactive::InteractiveSharedMany, spdz::preprocessing::FuelTank}, }; use crate::{net::Communicate, schemes::interactive::InteractiveShared}; use derive_more::{Add, AddAssign, Sub, SubAssign}; @@ -19,13 +19,12 @@ use ff::PrimeField; use rand::RngCore; use serde::{de::DeserializeOwned, Serialize}; -use self::preprocessing::ForSharing; +use futures_concurrency::prelude::*; +use std::error::Error; +use thiserror::Error; +use tracing::Instrument; pub mod preprocessing; -use std::{ - convert::Infallible, - error::{self, Error}, -}; // Should we allow Field or use PrimeField? #[derive( @@ -50,7 +49,12 @@ mod ops { use ff::PrimeField; - use super::Share; + use crate::{ + net::{agency::Broadcast, Id}, + schemes::spdz::{partial_opening, preprocessing}, + }; + + use super::{Share, SpdzParams}; impl AddAssign<&Self> for Share { fn add_assign(&mut self, rhs: &Self) { @@ -63,86 +67,99 @@ mod ops { *self -= *rhs; } } -} -impl Share { - #[must_use] - pub fn add_public(self, val: F, is_chosen_party: bool, params: &SpdzParams) -> Self { - let mac_key_share = params.mac_key_share; - let val_val = if is_chosen_party { val } else { F::ZERO }; - Share { - val: self.val + val_val, - mac: self.mac + val * mac_key_share, + // Mutliplication between a share and a public value + // This operation is symmetric + impl std::ops::Mul for Share { + type Output = Share; + + fn mul(self, rhs: F) -> Self::Output { + Share { + val: self.val * rhs, + mac: self.mac * rhs, + } } } - #[must_use] - pub fn sub_public(self, val: F, chosen_one: bool, params: &SpdzParams) -> Self { - let mac_key_share = params.mac_key_share; - let val_val = if chosen_one { val } else { F::ZERO }; - Share { - val: self.val - val_val, - mac: self.mac - val * mac_key_share, + impl std::ops::MulAssign<&F> for Share { + fn mul_assign(&mut self, rhs: &F) { + self.val *= *rhs; + self.mac *= *rhs; } } -} -// Mutliplication between a share and a public value -// This operation is symmetric -impl std::ops::Mul for Share { - type Output = Share; + impl Share { + #[must_use] + pub fn add_public(self, val: F, is_chosen_party: bool, params: &SpdzParams) -> Self { + let mac_key_share = params.mac_key_share; + let val_val = if is_chosen_party { val } else { F::ZERO }; + Share { + val: self.val + val_val, + mac: self.mac + val * mac_key_share, + } + } - fn mul(self, rhs: F) -> Self::Output { - Share { - val: self.val * rhs, - mac: self.mac * rhs, + #[must_use] + pub fn sub_public(self, val: F, chosen_one: bool, params: &SpdzParams) -> Self { + let mac_key_share = params.mac_key_share; + let val_val = if chosen_one { val } else { F::ZERO }; + Share { + val: self.val - val_val, + mac: self.mac - val * mac_key_share, + } } } -} -pub async fn secret_mult( - s1: Share, - s2: Share, - triplets: &mut preprocessing::Triplets, - params: &SpdzParams, - opened_values: &mut Vec, - network: &mut impl Broadcast, -) -> Result, preprocessing::PreProcError> -where - F: PrimeField + serde::Serialize + serde::de::DeserializeOwned, -{ - let triplet = match triplets.get_triplet() { - Ok(tri) => tri, - Err(e) => return Err(e), - }; - let is_chosen_party = params.who_am_i == Id(0); - - let e = s1 - triplet.a; - let d = s2 - triplet.b; - let e = partial_opening(&e, params, network, opened_values).await; - let d = partial_opening(&d, params, network, opened_values).await; - let res = - (triplet.c + triplet.b * e + triplet.a * d).add_public(e * d, is_chosen_party, params); - Ok(res) + // Harmonize this with the beaver impl. + pub async fn secret_mult( + s1: Share, + s2: Share, + triplets: &mut preprocessing::Triplets, + params: &SpdzParams, + opened_values: &mut Vec, + network: &mut impl Broadcast, + ) -> Result, preprocessing::PreProcError> + where + F: PrimeField + serde::Serialize + serde::de::DeserializeOwned, + { + let triplet = match triplets.get_triplet() { + Ok(tri) => tri, + Err(e) => return Err(e), + }; + let is_chosen_party = params.who_am_i == Id(0); + let (a, b, c) = triplet.shares; + + let e = s1 - a; + let d = s2 - b; + let e = partial_opening(&e, params, network, opened_values).await; + let d = partial_opening(&d, params, network, opened_values).await; + + let res = (c + b * e + a * d).add_public(e * d, is_chosen_party, params); + Ok(res) + } } +#[derive(Debug, Error)] +#[error("SpdzError: {0}")] +pub struct SpdzError(#[from] Box); + impl InteractiveShared for Share where F: PrimeField + serde::Serialize + serde::de::DeserializeOwned, { type Context = SpdzContext; type Value = F; - type Error = Infallible; + type Error = SpdzError; async fn share( ctx: &mut Self::Context, secret: Self::Value, _rng: impl RngCore + Send, mut coms: impl Communicate, - ) -> Result { + ) -> Result { let params = &ctx.params; - let for_sharing = &mut ctx.preprocessed.for_sharing; - let res = send_shares(&[secret], for_sharing, params, &mut coms) + let (fuel, rand) = &mut ctx.preprocessed.for_sharing.get_own(); + let res = send_shares(&[secret], fuel, rand, params, &mut coms) .await .unwrap(); Ok(res[0]) @@ -156,32 +173,49 @@ where ) -> Result, Self::Error> { let number_of_parties = Broadcast::size(&coms); let me = ctx.params.who_am_i; - let mut shares: Vec> = vec![]; - for turn in 0..number_of_parties { - let turn = Id(turn); - // TODO: Concurrency. - if turn == me { - let s = send_shares( - &[secret], - &mut ctx.preprocessed.for_sharing, - &ctx.params, - &mut coms, - ) - .await - .unwrap(); - shares.push(s[0]); - } else { - let s = receive_shares( - &mut coms, - turn, - &mut ctx.preprocessed.for_sharing, - &ctx.params, - ) + let (gateway, mut muxes) = mux::NetworkGateway::multiplexify(&mut coms, number_of_parties); + let params = &ctx.params; + let (my_fueltank, randomness, others) = ctx.preprocessed.for_sharing.split(); + + let mut special = muxes.remove(me.0); + + let futs: Vec<_> = muxes + .into_iter() + .zip(others) + .map(|(mut coms, fueltank)| async { + let id = fueltank.party.0; + let span = tracing::info_span!("Receiving", from = id); + let s = receive_shares(&mut coms, fueltank, params) + .instrument(span) + .await + .map(|s| s[0]); + drop(coms); + s + }) + .collect(); + let mine = async { + let span = tracing::info_span!("Sending"); + let s = send_shares(&[secret], my_fueltank, randomness, params, &mut special) + .instrument(span) .await - .unwrap(); - shares.push(s[0]); - } - } + .map(|s| s[0]); + drop(special); + s + }; + + let (my_result, results, driver) = (mine, futs.join(), gateway.drive()).join().await; + driver + .inspect_err(|e| tracing::error!("Gateway error: {e}")) + .map_err(|e| SpdzError(Box::new(e)))?; + + let mut shares: Vec<_> = results + .into_iter() + .try_collect() + .map_err(|e| SpdzError(e))?; + let my_share = my_result.map_err(|e| SpdzError(e))?; + + shares.insert(me.0, my_share); + tracing::info!("Succes!"); Ok(shares) } @@ -189,12 +223,12 @@ where ctx: &mut Self::Context, mut coms: impl Communicate, from: Id, - ) -> Result { + ) -> Result { let params = &ctx.params; - let for_sharing = &mut ctx.preprocessed.for_sharing; - let res = receive_shares(&mut coms, from, for_sharing, params) + let fueltank = &mut ctx.preprocessed.for_sharing.get_fuel_mut(from); + let res = receive_shares(&mut coms, fueltank, params) .await - .unwrap(); + .map_err(|e| SpdzError(e))?; Ok(res[0]) } @@ -202,8 +236,8 @@ where ctx: &mut Self::Context, share: Self, mut network: impl Communicate, - ) -> Result { - Ok(open_res(share, &mut network, &ctx.params, &ctx.opened_values).await) + ) -> Result { + open_res(share, &mut network, &ctx.params, &ctx.opened_values).await } } @@ -211,7 +245,7 @@ impl InteractiveSharedMany for Share where F: PrimeField + serde::Serialize + serde::de::DeserializeOwned, { - type VectorShare = crate::algebra::math::Vector>; + type VectorShare = Vector>; async fn share_many( ctx: &mut Self::Context, @@ -220,8 +254,8 @@ where mut coms: impl Communicate, ) -> Result { let params = &ctx.params; - let for_sharing = &mut ctx.preprocessed.for_sharing; - let res = send_shares(secret, for_sharing, params, &mut coms) + let (fuel, rand) = &mut ctx.preprocessed.for_sharing.get_own(); + let res = send_shares(secret, fuel, rand, params, &mut coms) .await .unwrap(); Ok(res.into()) @@ -234,34 +268,56 @@ where mut coms: impl Communicate, ) -> Result, Self::Error> { let number_of_parties = Broadcast::size(&coms); - let nums: Vec<_> = secret.into(); - let me = ctx.params.who_am_i; - let mut shares: Vec>> = vec![]; - for turn in 0..number_of_parties { - let turn = Id(turn); - // TODO: Concurrency. - if turn == me { - let s = send_shares( - &nums, - &mut ctx.preprocessed.for_sharing, - &ctx.params, - &mut coms, - ) - .await - .unwrap(); - shares.push(s.into()); - } else { - let s = receive_shares( - &mut coms, - turn, - &mut ctx.preprocessed.for_sharing, - &ctx.params, - ) - .await - .unwrap(); - shares.push(s.into()); - } - } + + let (gateway, mut muxes) = mux::NetworkGateway::multiplexify(&mut coms, number_of_parties); + let params = &ctx.params; + let me = params.who_am_i; + + let fuel: Vec<_> = ctx + .preprocessed + .for_sharing + .party_fuel + .iter() + .map(|tank| tank.party) + .collect(); + tracing::info!("Sharing as id = {me:?} with fueltanks {fuel:?}"); + let me2 = ctx.preprocessed.for_sharing.me; + tracing::debug!("Processed: {:?}", me2); + let (my_fueltank, randomness, others) = ctx.preprocessed.for_sharing.split(); + tracing::debug!("Party: {:?} Fueltank: {:?}", &me, &my_fueltank.party); + + let mut special = muxes.remove(me.0); + + let futs: Vec<_> = muxes + .into_iter() + .zip(others) + .map(|(mut coms, fueltank)| async move { + let id = fueltank.party.0; + let span = tracing::info_span!("Receiving", from = id); + let s = receive_shares(&mut coms, fueltank, params) + .instrument(span) + .await + .map(|s| s.into()); + drop(coms); + s + }) + .collect(); + let mine = async { + let s = send_shares(secret, my_fueltank, randomness, params, &mut special).await; + drop(special); + s + }; + + let (my_result, results, driver) = (mine, futs.join(), gateway.drive()).join().await; + driver + .inspect_err(|e| tracing::error!("Gateway error: {e}")) + .map_err(|e| SpdzError(Box::new(e)))?; + + let my_share = my_result.map_err(|e| SpdzError(e))?; + + let mut shares: Vec<_> = results.into_iter().map(|x| x.unwrap()).collect(); + shares.insert(me.0, my_share.into()); + Ok(shares) } @@ -271,10 +327,10 @@ where from: Id, ) -> Result { let params = &ctx.params; - let for_sharing = &mut ctx.preprocessed.for_sharing; - let res = receive_shares(&mut coms, from, for_sharing, params) + let fueltank = &mut ctx.preprocessed.for_sharing.get_fuel_mut(from); + let res = receive_shares(&mut coms, fueltank, params) .await - .unwrap(); + .map_err(|e| SpdzError(e))?; Ok(res.into()) } @@ -297,48 +353,31 @@ where } } -// TODO: Kill this with fire -pub async fn share( - secrets: Option>, // TODO: remove option. - for_sharing: &mut ForSharing, - params: &SpdzParams, - who_is_sending: Id, - network: &mut impl Broadcast, -) -> Result>, Box> { - let is_chosen_one = params.who_am_i == who_is_sending; - if is_chosen_one { - send_shares(&secrets.unwrap(), for_sharing, params, network).await - } else { - receive_shares(network, who_is_sending, for_sharing, params).await - } -} - async fn receive_shares( network: &mut impl Broadcast, - who_is_sending: Id, - for_sharing: &mut ForSharing, + fueltank: &mut FuelTank, params: &SpdzParams, -) -> Result>, Box> { - let corrections: Vec<_> = match network.recv_from(who_is_sending).await { +) -> Result>, Box> { + let corrections: Vec<_> = match network.recv_from(fueltank.party).await { Ok(vec) => vec, Err(e) => return Err(e.into()), }; - Ok(create_shares_from( + Ok(create_foreign_share( &corrections, - for_sharing, - who_is_sending, + &mut fueltank.shares, params, )?) } async fn send_shares( secrets: &[F], - for_sharing: &mut ForSharing, + fueltank: &mut FuelTank, + randomness: &mut Vec, params: &SpdzParams, network: &mut impl Broadcast, -) -> Result>, Box> { +) -> Result>, Box> { // TODO: return some error - let res = create_shares(secrets, for_sharing, params); + let res = create_shares(secrets, fueltank, randomness, params); let (shares, corrections) = match res { Ok((shares, corrections)) => (shares, corrections), Err(e) => return Err(e.into()), @@ -352,45 +391,56 @@ async fn send_shares( fn create_shares( vals: &[F], - for_sharing: &mut ForSharing, + fueltank: &mut FuelTank, + randomness: &mut Vec, params: &SpdzParams, ) -> Result<(Vec>, Vec), preprocessing::PreProcError> { - let mut res_share: Vec> = vec![]; - let mut res_correction: Vec = vec![]; - for val in vals { - let Some(r) = for_sharing.rand_known_to_me.vals.pop() else { - return Err(preprocessing::PreProcError::MissingForSharingElement); - }; - let Some(r_share) = for_sharing.rand_known_to_i.shares[params.who_am_i.0].pop() else { - return Err(preprocessing::PreProcError::MissingForSharingElement); - }; - let correction = *val - r; - let share = r_share.add_public(correction, params.who_am_i == Id(0), params); - res_share.push(share); - res_correction.push(correction); + assert_eq!( + fueltank.party, params.who_am_i, + "Fueltank does not match params" + ); + let n = vals.len(); + let my_randomness = randomness; + let their_randomness = &mut fueltank.shares; + + // We will consume the last `n` values, so we need to ensure their are `n` + if n > my_randomness.len() || n > their_randomness.len() { + return Err(preprocessing::PreProcError::MissingForSharingElement); } + + let (res_share, res_correction) = vals + .iter() + .zip(my_randomness.drain(my_randomness.len() - n..).rev()) + .zip(their_randomness.drain(their_randomness.len() - n..).rev()) + .map(|((val, r), r_share)| { + let correction = *val - r; + let share = r_share.add_public(correction, params.who_am_i == Id(0), params); + (share, correction) + }) + .unzip(); + Ok((res_share, res_correction)) } // When receiving a share, the party receiving it needs to know who send it. -fn create_shares_from( +fn create_foreign_share( corrections: &[F], - for_sharing: &mut ForSharing, - who_is_sending: Id, + preshares: &mut Vec>, params: &SpdzParams, ) -> Result>, preprocessing::PreProcError> { - let prep_rand_len = for_sharing.rand_known_to_i.shares[who_is_sending.0].len(); + // TODO: Kill this vvvv + // We really should be able to pass in a list that is only `m` long + // and drain it. + let n = corrections.len(); - if n > for_sharing.rand_known_to_i.shares[who_is_sending.0].len() { + if n > preshares.len() { return Err(preprocessing::PreProcError::MissingForSharingElement); } - let mut randoms = - for_sharing.rand_known_to_i.shares[who_is_sending.0].split_off(prep_rand_len - n); - // TODO consider changing send_shares to also use split_off instead of pop, so we don't need to reverse. - randoms.reverse(); - let rc = randoms.iter().zip(corrections); - let shares: Vec> = rc - .map(|(&r, &c)| r.add_public(c, params.who_am_i == Id(0), params)) + let shares: Vec> = preshares + .drain(preshares.len() - n..) + .rev() + .zip(corrections) + .map(|(r, &c)| r.add_public(c, params.who_am_i == Id(0), params)) .collect(); Ok(shares) } @@ -400,14 +450,14 @@ async fn partial_opening, params: &SpdzParams, network: &mut impl Broadcast, - partially_opened_vals: &mut Vec, + partially_opened: &mut Vec, ) -> F { let candidate_vals = network .symmetric_broadcast(candidate_share.val) .await .unwrap(); let candidate_val = candidate_vals.iter().sum(); - partially_opened_vals.push(candidate_val * params.mac_key_share - candidate_share.mac); + partially_opened.push(candidate_val * params.mac_key_share - candidate_share.mac); candidate_val } @@ -421,7 +471,9 @@ pub struct SpdzParams { // If we do not want the context to be public, we probably need some getter functions - and some alter functions. (TODO) #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct SpdzContext { + /// Needs to be verified later pub opened_values: Vec, + /// Base parameters (key + id) pub params: SpdzParams, pub preprocessed: preprocessing::PreprocessedValues, } @@ -463,27 +515,25 @@ where } let opened_shares = opened_vals_sum.iter().zip(macs_to_shares); - let mut ds: Vec = opened_shares + let ds: Vec = opened_shares .map(|(v, m)| params.mac_key_share * v - m) .collect(); - let this_went_well = check_all_d(&mut ds, network, random_element).await; + let this_went_well = check_all_d(&ds, network, random_element).await; if this_went_well { opened_vals_sum } else { panic!("The check did not go though"); } } -// TODO: return an option or a result instead. - result probably makes most sense, but then we might want the costom errors first pub async fn open_res( share_to_open: Share, network: &mut impl Broadcast, params: &SpdzParams, opened_values: &[F], -) -> F +) -> Result where F: PrimeField + serde::Serialize + serde::de::DeserializeOwned, { - // TODO rerun error instead // TODO: consider just calling check all - needs a random element though - either a generator or an element. //check_all_d(opened_values, network, random_element) assert!( @@ -496,29 +546,36 @@ where let opened_shares = network .symmetric_broadcast(share_to_open.val) .await - .unwrap(); + .map_err(|e| SpdzError(Box::new(e)))?; let opened_val: F = opened_shares.iter().sum(); let d = opened_val * params.mac_key_share - share_to_open.mac; - let this_went_well = check_one_d(d, network).await; + let this_went_well = check_one_d(d, network).await?; if this_went_well { - opened_val + Ok(opened_val) } else { + // TODO: Proper errors panic!("The check did not go though"); } } // An element and its mac are accepted, if the sum of the corresponding d from each party is zero. -async fn check_one_d(d: F, network: &mut impl Broadcast) -> bool +async fn check_one_d(d: F, network: &mut impl Broadcast) -> Result where F: PrimeField + serde::Serialize + serde::de::DeserializeOwned, { let (c, s) = commit(&d); - let cs = network.symmetric_broadcast((c, s)).await.unwrap(); - let ds = network.symmetric_broadcast(d).await.unwrap(); + let cs = network + .symmetric_broadcast((c, s)) + .await + .map_err(|e| SpdzError(Box::new(e)))?; + let ds = network + .symmetric_broadcast(d) + .await + .map_err(|e| SpdzError(Box::new(e)))?; let dcs = ds.iter().zip(cs.iter()); let verify_commitments = dcs.fold(true, |acc, (d, (c, s))| verify_commit(d, c, s) && acc); let ds_sum: F = ds.iter().sum(); - (ds_sum == 0.into()) && verify_commitments + Ok((ds_sum == 0.into()) && verify_commitments) } // An element is accepted, if the sum of the corresponding d from each party is zero. @@ -527,7 +584,7 @@ where // Now the random element is commited to and bradcasted together with the d's, instead of after. // - This is not problematic as the d's can't be altered after they are committed to, so they still can't depend on the random element pub async fn check_all_d( - partially_opened_vals: &mut Vec, + partially_opened_vals: &[F], network: &mut impl Broadcast, random_element: F, ) -> bool @@ -550,7 +607,6 @@ where // Then we make a random linear combination of all the values, commit, broadcast, verify that it is zero let lin_comp = linear_combinations(random_val_shares.into_iter().sum(), partially_opened_vals); - partially_opened_vals.clear(); let lin_comps_commitments = network .symmetric_broadcast(commit(&lin_comp)) .await @@ -565,12 +621,12 @@ where zero == F::from_u128(0) } -fn linear_combinations(random_element: F, elements: &mut [F]) -> F { +fn linear_combinations(random_element: F, elements: &[F]) -> F { let r_elms: Vec = (1..=elements.len()) .map(|i| power(&random_element, i)) .collect(); elements - .iter_mut() + .iter() .zip(r_elms) .fold(F::from_u128(0), |acc, (e, r)| acc + r * (*e)) } @@ -584,15 +640,92 @@ fn power>(base: &F, e #[cfg(test)] mod test { + use crate::schemes::spdz::{self, preprocessing::PreShareTank}; use ff::Field; use rand::thread_rng; use rand::SeedableRng; use std::io::Seek; - use crate::{algebra::element::Element32, net::network::InMemoryNetwork, testing::Cluster}; + use crate::{ + algebra::element::Element32, net::network::InMemoryNetwork, + schemes::spdz::ops::secret_mult, testing::Cluster, + }; use super::*; + #[tokio::test] + async fn symmetric_sharing() { + let rng = rand::rngs::mock::StepRng::new(7, 32); + let (ctxs, _secrets) = preprocessing::dealer_preproc::(rng, &[1, 1, 1], 0, 3); + + let res: Vec> = Cluster::new(3) + .with_args(ctxs) + .run_with_args(|mut coms, mut ctx| async move { + let rng = rand::rngs::mock::StepRng::new(7, 32); + let secret = Element32::from(33u32); + let shares = spdz::Share::symmetric_share(&mut ctx, secret, rng, &mut coms) + .instrument(tracing::info_span!("Sharing")) + .await?; + + let share = shares[0] + shares[1] + shares[2]; + spdz::Share::recombine(&mut ctx, share, &mut coms) + .instrument(tracing::info_span!("Recombining")) + .await + .map(u32::from) + }) + .await + .unwrap(); + + let res: Vec<_> = res.into_iter().map(|res| res.unwrap()).collect(); + assert_eq!(&res, &[99, 99, 99u32]); + } + + #[tokio::test] + async fn symmetric_sharing_many() { + let rng = rand::rngs::mock::StepRng::new(7, 32); + let (ctxs, _secrets) = preprocessing::dealer_preproc::(rng, &[1, 1, 1], 0, 3); + + let res: Vec> = Cluster::new(3) + .with_args(ctxs) + .run_with_args(|mut coms, mut ctx| async move { + let rng = rand::rngs::mock::StepRng::new(7, 32); + let secret = Element32::from(33u32); + let shares = spdz::Share::symmetric_share_many(&mut ctx, &[secret], rng, &mut coms) + .instrument(tracing::info_span!("Sharing")) + .await?; + + let share = shares[0].clone() + &shares[1] + &shares[2]; + spdz::Share::recombine_many(&mut ctx, share, &mut coms) + .instrument(tracing::info_span!("Recombining")) + .await + .map(|x| x[0]) + .map(u32::from) + }) + .await + .unwrap(); + + let res: Vec<_> = res.into_iter().map(|res| res.unwrap()).collect(); + assert_eq!(&res, &[99, 99, 99u32]); + } + + // Legacy function only used in tests + pub async fn share( + secrets: Option>, // TODO: remove option. + for_sharing: &mut PreShareTank, + params: &SpdzParams, + who_is_sending: Id, + network: &mut impl Broadcast, + ) -> Result>, Box> { + let is_chosen_one = params.who_am_i == who_is_sending; + if is_chosen_one { + let (fuel, rand) = for_sharing.get_own(); + send_shares(&secrets.unwrap(), fuel, rand, params, network).await + } else { + let fueltank = for_sharing.get_fuel_mut(who_is_sending); + receive_shares(network, fueltank, params).await + } + } + // All these tests use dealer preprosessing fn dummie_preproc() -> ( SpdzContext, @@ -606,7 +739,7 @@ mod test { let number_of_parties = 2; let (mut contexts, secret_values) = preprocessing::dealer_preproc( rng, - known_to_each, + &known_to_each, number_of_triplets, number_of_parties, ); @@ -624,7 +757,7 @@ mod test { let number_of_parties = 2; let (mut contexts, secret_values) = preprocessing::dealer_preproc( rng, - known_to_each, + &known_to_each, number_of_triplets, number_of_parties, ); @@ -637,10 +770,10 @@ mod test { let p2_params = p2_context.params; let mut p1_preprocessed = p1_context.preprocessed; let mut p2_preprocessed = p2_context.preprocessed; - let p1_known_to_pi = p1_preprocessed.for_sharing.rand_known_to_i.shares; - let p2_known_to_pi = p2_preprocessed.for_sharing.rand_known_to_i.shares; - let p1_known_to_me = p1_preprocessed.for_sharing.rand_known_to_me.vals; - let p2_known_to_me = p2_preprocessed.for_sharing.rand_known_to_me.vals; + let p1_known_to_pi: Vec> = p1_preprocessed.for_sharing.bad_habits(); + let p2_known_to_pi = p2_preprocessed.for_sharing.bad_habits(); + let p1_known_to_me = p1_preprocessed.for_sharing.my_randomness; + let p2_known_to_me = p2_preprocessed.for_sharing.my_randomness; let p1_triplet_1 = p1_preprocessed .triplets .get_triplet() @@ -676,18 +809,18 @@ mod test { assert!(s1.val == s3); assert!(s1.mac == s3 * mac); - let a1 = p1_triplet_1.a + p2_triplet_1.a; - let b1 = p1_triplet_1.b + p2_triplet_1.b; - let c1 = p1_triplet_1.c + p2_triplet_1.c; + let a1 = p1_triplet_1.shares.0 + p2_triplet_1.shares.0; + let b1 = p1_triplet_1.shares.1 + p2_triplet_1.shares.1; + let c1 = p1_triplet_1.shares.2 + p2_triplet_1.shares.2; assert!(a1.val * b1.val == c1.val); assert!(a1.val * mac == a1.mac); assert!(b1.val * mac == b1.mac); assert!(c1.val * mac == c1.mac); - let a2 = p1_triplet_2.a + p2_triplet_2.a; - let b2 = p1_triplet_2.b + p2_triplet_2.b; - let c2 = p1_triplet_2.c + p2_triplet_2.c; + let a2 = p1_triplet_2.shares.0 + p2_triplet_2.shares.0; + let b2 = p1_triplet_2.shares.1 + p2_triplet_2.shares.1; + let c2 = p1_triplet_2.shares.2 + p2_triplet_2.shares.2; assert!(a2.val * b2.val == c2.val); assert!(a2.val * mac == a2.mac); @@ -704,16 +837,17 @@ mod test { // P1 shares an element let mut p1_prepros = p1_context.preprocessed; let elm1 = F::from_u128(56u128); + + let (fueltank, randomness) = p1_prepros.for_sharing.get_own(); let (elm1_1_v, correction_v) = - create_shares(&[elm1], &mut p1_prepros.for_sharing, &p1_context.params) + create_shares(&[elm1], fueltank, randomness, &p1_context.params) .expect("Something went wrong while P1 was sending the share."); let (elm1_1, correction) = (elm1_1_v[0], correction_v[0]); let mut p2_prepros = p2_context.preprocessed; - let elm1_2 = create_shares_from( + let elm1_2 = create_foreign_share( &[correction], - &mut p2_prepros.for_sharing, - Id(0), + &mut p2_prepros.for_sharing.party_fuel[0].shares, &p2_context.params, ) .expect("Something went wrong while P2 was receiving the share.")[0]; @@ -722,15 +856,15 @@ mod test { // P2 shares an element let elm2 = F::from_u128(18u128); + let (fueltank, randomness) = p2_prepros.for_sharing.get_own(); let (elm2_2_v, correction_v) = - create_shares(&[elm2], &mut p2_prepros.for_sharing, &p2_context.params) + create_shares(&[elm2], fueltank, randomness, &p2_context.params) .expect("Something went wrong when P2 was sending the share"); let (elm2_2, correction) = (elm2_2_v[0], correction_v[0]); - let elm2_1 = create_shares_from( + let elm2_1 = create_foreign_share( &[correction], - &mut p1_prepros.for_sharing, - Id(1), + &mut p1_prepros.for_sharing.party_fuel[1].shares, &p1_context.params, ) .expect("Something went wrong while P1 was receiving the share")[0]; @@ -749,7 +883,7 @@ mod test { let number_of_parties = 2; let (mut contexts, _) = preprocessing::dealer_preproc( rng, - known_to_each, + &known_to_each, number_of_triplets, number_of_parties, ); @@ -778,7 +912,8 @@ mod test { &context.opened_values, //F::from_u128(8u128), ) - .await; + .await + .unwrap(); //.await.pop().expect("There should be a result"); assert!(val == res); } @@ -808,19 +943,15 @@ mod test { let (mut p1_context, mut p2_context, secret_values) = dummie_preproc(); // P1 shares an element + let (fuel, rand) = p1_context.preprocessed.for_sharing.get_own(); let elm1 = F::from_u128(56u128); - let (elm1_1_v, correction_v) = create_shares( - &[elm1], - &mut p1_context.preprocessed.for_sharing, - &p1_context.params, - ) - .expect("Something went wrong when P1 was sending the element."); + let (elm1_1_v, correction_v) = create_shares(&[elm1], fuel, rand, &p1_context.params) + .expect("Something went wrong when P1 was sending the element."); let (elm1_1, correction) = (elm1_1_v[0], correction_v[0]); - let elm1_2 = create_shares_from( + let elm1_2 = create_foreign_share( &[correction], - &mut (p2_context.preprocessed.for_sharing), - Id(0), + p2_context.preprocessed.for_sharing.get_fuel_vec_mut(Id(0)), &p2_context.params, ) .expect("Something went worng when P2 was receiving the element")[0]; @@ -829,18 +960,14 @@ mod test { // P2 shares an element let elm2 = F::from_u128(18u128); - let (elm2_2_v, correction_v) = create_shares( - &[elm2], - &mut p2_context.preprocessed.for_sharing, - &p2_context.params, - ) - .expect("Something went wrong when P2 was sending the element."); + let (fuel, rand) = p2_context.preprocessed.for_sharing.get_own(); + let (elm2_2_v, correction_v) = create_shares(&[elm2], fuel, rand, &p2_context.params) + .expect("Something went wrong when P2 was sending the element."); let (elm2_2, correction) = (elm2_2_v[0], correction_v[0]); - let elm2_1 = create_shares_from( + let elm2_1 = create_foreign_share( &[correction], - &mut p1_context.preprocessed.for_sharing, - Id(1), + p1_context.preprocessed.for_sharing.get_fuel_vec_mut(Id(1)), &p1_context.params, ) .expect("Something went worng when P1 was receiving the element")[0]; @@ -866,7 +993,7 @@ mod test { partial_opening(&elm, ¶ms, &mut network, &mut partially_opened_vals).await; assert!(val1_guess == val1); for d in partially_opened_vals { - if !check_one_d(d, &mut network).await { + if !check_one_d(d, &mut network).await.unwrap() { // TODO: check that it actually fails, if there is a wrong value somewhere. panic!("Someone cheated") } @@ -905,18 +1032,14 @@ mod test { // P1 shares an element let elm1 = F::from_u128(56u128); - let (elm1_1_v, correction_v) = create_shares( - &[elm1], - &mut p1_context.preprocessed.for_sharing, - &p1_context.params, - ) - .expect("Something went wrong when P1 was sending the element."); + let (fuel, rand) = p1_context.preprocessed.for_sharing.get_own(); + let (elm1_1_v, correction_v) = create_shares(&[elm1], fuel, rand, &p1_context.params) + .expect("Something went wrong when P1 was sending the element."); let (elm1_1, correction) = (elm1_1_v[0], correction_v[0]); - let elm1_2 = create_shares_from( + let elm1_2 = create_foreign_share( &[correction], - &mut (p2_context.preprocessed.for_sharing), - Id(0), + p2_context.preprocessed.for_sharing.get_fuel_vec_mut(Id(0)), &p2_context.params, ) .expect("Something went worng when P2 was receiving the element")[0]; @@ -925,18 +1048,14 @@ mod test { // P2 shares an element let elm2 = F::from_u128(18u128); - let (elm2_2_v, correction_v) = create_shares( - &[elm2], - &mut p2_context.preprocessed.for_sharing, - &p2_context.params, - ) - .expect("Something went wrong when P2 was sending the element."); + let (fuel, rand) = p2_context.preprocessed.for_sharing.get_own(); + let (elm2_2_v, correction_v) = create_shares(&[elm2], fuel, rand, &p2_context.params) + .expect("Something went wrong when P2 was sending the element."); let (elm2_2, correction) = (elm2_2_v[0], correction_v[0]); - let elm2_1 = create_shares_from( + let elm2_1 = create_foreign_share( &[correction], - &mut p1_context.preprocessed.for_sharing, - Id(1), + p1_context.preprocessed.for_sharing.get_fuel_vec_mut(Id(1)), &p1_context.params, ) .expect("Something went worng when P1 was receiving the element")[0]; @@ -963,9 +1082,10 @@ mod test { partial_opening(&elm, ¶ms, &mut network, &mut partially_opened_vals).await; assert!(val1_guess == val1); //if !check_all_d(&partially_opened_vals, &mut network).await { - if !check_all_d(&mut partially_opened_vals, &mut network, random_element).await { + if !check_all_d(&partially_opened_vals, &mut network, random_element).await { panic!("Someone cheated") } + partially_opened_vals.clear(); } let mut taskset = tokio::task::JoinSet::new(); @@ -994,16 +1114,15 @@ mod test { // P1 shares an element let mut p1_prepros = p1_context.preprocessed; let elm1 = F::from_u128(56u128); - let (elm1_1_v, correction_v) = - create_shares(&[elm1], &mut p1_prepros.for_sharing, &p1_context.params) - .expect("Something went wrong when P1 was sending the element."); + let (fuel, rand) = p1_prepros.for_sharing.get_own(); + let (elm1_1_v, correction_v) = create_shares(&[elm1], fuel, rand, &p1_context.params) + .expect("Something went wrong when P1 was sending the element."); let (elm1_1, correction) = (elm1_1_v[0], correction_v[0]); let mut p2_prepros = p2_context.preprocessed; - let elm1_2 = create_shares_from( + let elm1_2 = create_foreign_share( &[correction], - &mut p2_prepros.for_sharing, - Id(0), + p2_prepros.for_sharing.get_fuel_vec_mut(Id(0)), &p2_context.params, ) .expect("Something went wrong when P2 was receiving the element.")[0]; @@ -1012,15 +1131,14 @@ mod test { // P2 shares an element let elm2 = F::from_u128(18u128); - let (elm2_2_v, correction_v) = - create_shares(&[elm2], &mut p2_prepros.for_sharing, &p2_context.params) - .expect("Something went wrong when P2 was sending the element."); + let (fuel, rand) = p2_prepros.for_sharing.get_own(); + let (elm2_2_v, correction_v) = create_shares(&[elm2], fuel, rand, &p2_context.params) + .expect("Something went wrong when P2 was sending the element."); let (elm2_2, correction) = (elm2_2_v[0], correction_v[0]); - let elm2_1 = create_shares_from( + let elm2_1 = create_foreign_share( &[correction], - &mut p1_prepros.for_sharing, - Id(1), + p1_prepros.for_sharing.get_fuel_vec_mut(Id(1)), &p1_context.params, ) .expect("Something went wrong when P1 was receiving the element.")[0]; @@ -1044,17 +1162,16 @@ mod test { // P1 shares an element let mut p1_prepros = p1_context.preprocessed; let elm1 = F::from_u128(56u128); - let (elm1_1, correction) = - match create_shares(&[elm1], &mut p1_prepros.for_sharing, &p1_context.params) { - Ok((e, c)) => (e[0], c[0]), - Err(_) => panic!(), - }; + let (fuel, rand) = p1_prepros.for_sharing.get_own(); + let (elm1_1, correction) = match create_shares(&[elm1], fuel, rand, &p1_context.params) { + Ok((e, c)) => (e[0], c[0]), + Err(_) => panic!(), + }; let mut p2_prepros = p2_context.preprocessed; - let elm1_2 = match create_shares_from( + let elm1_2 = match create_foreign_share( &[correction], - &mut p2_prepros.for_sharing, - Id(0), + p2_prepros.for_sharing.get_fuel_vec_mut(Id(0)), &p2_context.params, ) { Ok(s) => s[0], @@ -1065,16 +1182,15 @@ mod test { // P2 shares an element let elm2 = F::from_u128(18u128); - let (elm2_2, correction) = - match create_shares(&[elm2], &mut p2_prepros.for_sharing, &p2_context.params) { - Ok((e, c)) => (e[0], c[0]), - Err(_) => panic!(), - }; + let (fuel, rand) = p2_prepros.for_sharing.get_own(); + let (elm2_2, correction) = match create_shares(&[elm2], fuel, rand, &p2_context.params) { + Ok((e, c)) => (e[0], c[0]), + Err(_) => panic!(), + }; - let elm2_1 = match create_shares_from( + let elm2_1 = match create_foreign_share( &[correction], - &mut p1_prepros.for_sharing, - Id(1), + p1_prepros.for_sharing.get_fuel_vec_mut(Id(1)), &p1_context.params, ) { Ok(s) => s[0], @@ -1099,21 +1215,20 @@ mod test { let pub_constant = F::from_u128(8711u128); // P1 shares an element let mut p1_prepros = p1_context.preprocessed; + let (fuel, rand) = p1_prepros.for_sharing.get_own(); let elm1 = F::from_u128(56u128); - let (elm1_1, correction) = - match create_shares(&[elm1], &mut p1_prepros.for_sharing, &p1_context.params) { - Ok((e, c)) => (e[0], c[0]), - Err(e) => { - println!("Error: {}", e); - panic!() - } - }; + let (elm1_1, correction) = match create_shares(&[elm1], fuel, rand, &p1_context.params) { + Ok((e, c)) => (e[0], c[0]), + Err(e) => { + println!("Error: {}", e); + panic!() + } + }; let mut p2_prepros = p2_context.preprocessed; - let elm1_2 = match create_shares_from( + let elm1_2 = match create_foreign_share( &[correction], - &mut p2_prepros.for_sharing, - Id(0), + p2_prepros.for_sharing.get_fuel_vec_mut(Id(0)), &p2_context.params, ) { Ok(s) => s[0], @@ -1139,17 +1254,16 @@ mod test { // P1 shares an element let p1_prepros = &mut p1_context.preprocessed; let elm1 = F::from_u128(56u128); - let (elm1_1, correction) = - match create_shares(&[elm1], &mut p1_prepros.for_sharing, &p1_context.params) { - Ok((e, c)) => (e[0], c[0]), - Err(_) => panic!(), - }; + let (fuel, rand) = p1_prepros.for_sharing.get_own(); + let (elm1_1, correction) = match create_shares(&[elm1], fuel, rand, &p1_context.params) { + Ok((e, c)) => (e[0], c[0]), + Err(_) => panic!(), + }; let p2_prepros = &mut p2_context.preprocessed; - let elm1_2 = match create_shares_from( + let elm1_2 = match create_foreign_share( &[correction], - &mut p2_prepros.for_sharing, - Id(0), + p2_prepros.for_sharing.get_fuel_vec_mut(Id(0)), &p2_context.params, ) { Ok(s) => s[0], @@ -1160,16 +1274,15 @@ mod test { // P2 shares an element let elm2 = F::from_u128(18u128); - let (elm2_2, correction) = - match create_shares(&[elm2], &mut p2_prepros.for_sharing, &p2_context.params) { - Ok((e, c)) => (e[0], c[0]), - Err(_) => panic!(), - }; + let (fuel, rand) = p2_prepros.for_sharing.get_own(); + let (elm2_2, correction) = match create_shares(&[elm2], fuel, rand, &p2_context.params) { + Ok((e, c)) => (e[0], c[0]), + Err(_) => panic!(), + }; - let elm2_1 = match create_shares_from( + let elm2_1 = match create_foreign_share( &[correction], - &mut p1_prepros.for_sharing, - Id(1), + p1_prepros.for_sharing.get_fuel_vec_mut(Id(1)), &p1_context.params, ) { Ok(s) => s[0], @@ -1214,7 +1327,8 @@ mod test { .await; assert!(expected_res.val == res); let rng = rand::rngs::mock::StepRng::new(42, 7); - assert!(check_all_d(&mut context.opened_values, &mut network, F::random(rng)).await); + assert!(check_all_d(&context.opened_values, &mut network, F::random(rng)).await); + context.opened_values.clear(); let res = open_res( res_share, @@ -1222,7 +1336,8 @@ mod test { &context.params, &context.opened_values, ) - .await; + .await + .unwrap(); assert!(expected_res.val == res); } @@ -1254,17 +1369,16 @@ mod test { // P1 shares an element let mut p1_prepros = p1_context.preprocessed; let elm1 = F::from_u128(56u128); - let (elm1_1, correction) = - match create_shares(&[elm1], &mut p1_prepros.for_sharing, &p1_context.params) { - Ok((e, c)) => (e[0], c[0]), - Err(_) => panic!(), - }; + let (fuel, rand) = p1_prepros.for_sharing.get_own(); + let (elm1_1, correction) = match create_shares(&[elm1], fuel, rand, &p1_context.params) { + Ok((e, c)) => (e[0], c[0]), + Err(_) => panic!(), + }; let mut p2_prepros = p2_context.preprocessed; - let elm1_2 = match create_shares_from( + let elm1_2 = match create_foreign_share( &[correction], - &mut p2_prepros.for_sharing, - Id(0), + p2_prepros.for_sharing.get_fuel_vec_mut(Id(0)), &p2_context.params, ) { Ok(s) => s[0], @@ -1298,17 +1412,16 @@ mod test { // P1 shares an element let mut p1_prepros = p1_context.preprocessed; let elm1 = F::from_u128(56u128); + let (fuel, rand) = p1_prepros.for_sharing.get_own(); let (elm1_1, correction) = { - let (e, c) = - create_shares(&[elm1], &mut p1_prepros.for_sharing, &p1_context.params).unwrap(); + let (e, c) = create_shares(&[elm1], fuel, rand, &p1_context.params).unwrap(); (e[0], c[0]) }; let mut p2_prepros = p2_context.preprocessed; - let elm1_2 = create_shares_from( + let elm1_2 = create_foreign_share( &[correction], - &mut p2_prepros.for_sharing, - Id(0), + p2_prepros.for_sharing.get_fuel_vec_mut(Id(0)), &p2_context.params, ) .unwrap()[0]; @@ -1352,7 +1465,7 @@ mod test { let number_of_parties = 2; let (mut contexts, _secret_values) = preprocessing::dealer_preproc( rng, - known_to_each, + &known_to_each, number_of_triplets, number_of_parties, ); @@ -1431,10 +1544,13 @@ mod test { // Checking all partially opened values let mut rng = rand_chacha::ChaCha20Rng::from_entropy(); let random_element = F::random(&mut rng); - assert!(check_all_d(&mut context.opened_values, &mut network, random_element).await); + assert!(check_all_d(&context.opened_values, &mut network, random_element).await); + context.opened_values.clear(); // opening(and checking) val_5 - let res = open_res(val_5, &mut network, &context.params, &context.opened_values).await; + let res = open_res(val_5, &mut network, &context.params, &context.opened_values) + .await + .unwrap(); assert!(res == F::from_u128(20u128)); } let mut taskset = tokio::task::JoinSet::new(); @@ -1465,7 +1581,7 @@ mod test { let number_of_parties = 2; let (mut contexts, _secret_values) = preprocessing::dealer_preproc( rng, - known_to_each, + &known_to_each, number_of_triplets, number_of_parties, ); @@ -1534,7 +1650,7 @@ mod test { let number_of_parties = 2; let (mut contexts, _secret_values) = preprocessing::dealer_preproc( rng, - known_to_each, + &known_to_each, number_of_triplets, number_of_parties, ); @@ -1643,25 +1759,25 @@ mod test { let number_of_triplets = 2; preprocessing::write_context( &mut files, - known_to_each, + &known_to_each, number_of_triplets, F::from_u128(0u128), ) .unwrap(); files[0].rewind().unwrap(); files[1].rewind().unwrap(); - let p1_context: SpdzContext = preprocessing::load_context(&mut files[0]); - let p2_context: SpdzContext = preprocessing::load_context(&mut files[1]); + let p1_context: SpdzContext = preprocessing::load_context(&mut files[0]).unwrap(); + let p2_context: SpdzContext = preprocessing::load_context(&mut files[1]).unwrap(); // unpacking let p1_params = p1_context.params; let p2_params = p2_context.params; let mac = p1_params.mac_key_share + p2_params.mac_key_share; let mut p1_preprocessed = p1_context.preprocessed; let mut p2_preprocessed = p2_context.preprocessed; - let p1_known_to_pi = p1_preprocessed.for_sharing.rand_known_to_i.shares; - let p2_known_to_pi = p2_preprocessed.for_sharing.rand_known_to_i.shares; - let p1_known_to_me = p1_preprocessed.for_sharing.rand_known_to_me.vals; - let p2_known_to_me = p2_preprocessed.for_sharing.rand_known_to_me.vals; + let p1_known_to_pi = p1_preprocessed.for_sharing.bad_habits(); + let p2_known_to_pi = p2_preprocessed.for_sharing.bad_habits(); + let p1_known_to_me = p1_preprocessed.for_sharing.my_randomness; + let p2_known_to_me = p2_preprocessed.for_sharing.my_randomness; let p1_triplet_1 = p1_preprocessed .triplets .get_triplet() @@ -1695,18 +1811,18 @@ mod test { assert!(s1.val == s3); assert!(s1.mac == s3 * mac); - let a1 = p1_triplet_1.a + p2_triplet_1.a; - let b1 = p1_triplet_1.b + p2_triplet_1.b; - let c1 = p1_triplet_1.c + p2_triplet_1.c; + let a1 = p1_triplet_1.shares.0 + p2_triplet_1.shares.0; + let b1 = p1_triplet_1.shares.1 + p2_triplet_1.shares.1; + let c1 = p1_triplet_1.shares.2 + p2_triplet_1.shares.2; assert!(a1.val * b1.val == c1.val); assert!(a1.val * mac == a1.mac); assert!(b1.val * mac == b1.mac); assert!(c1.val * mac == c1.mac); - let a2 = p1_triplet_2.a + p2_triplet_2.a; - let b2 = p1_triplet_2.b + p2_triplet_2.b; - let c2 = p1_triplet_2.c + p2_triplet_2.c; + let a2 = p1_triplet_2.shares.0 + p2_triplet_2.shares.0; + let b2 = p1_triplet_2.shares.1 + p2_triplet_2.shares.1; + let c2 = p1_triplet_2.shares.2 + p2_triplet_2.shares.2; assert!(a2.val * b2.val == c2.val); assert!(a2.val * mac == a2.mac); diff --git a/src/schemes/spdz/preprocessing.rs b/src/schemes/spdz/preprocessing.rs index 7f510e8..1a87a6f 100644 --- a/src/schemes/spdz/preprocessing.rs +++ b/src/schemes/spdz/preprocessing.rs @@ -1,20 +1,19 @@ // Preprocessing use crate::{ + algebra::math::Vector, net::Id, - schemes::spdz::{self, SpdzContext}, + protocols::beaver, + schemes::{ + spdz::{self, SpdzContext}, + Reserve, + }, }; use bincode; use ff::PrimeField; -use rand::SeedableRng; +use rand::{Rng, SeedableRng}; use serde::{de::DeserializeOwned, Serialize}; -use std::{ - error::Error, - fmt, - fs::File, - io::{self, Write}, - path::Path, -}; +use std::{error::Error, fmt, fs::File, io::Write, path::Path}; #[derive(Debug, Clone, PartialEq)] pub enum PreProcError { @@ -35,26 +34,132 @@ impl fmt::Display for PreProcError { } } +impl Reserve for spdz::SpdzContext { + fn reserve(&mut self, amount: usize) -> Self { + fn inner(list: &mut Vec, n: usize) -> Vec { + let mut new = list.split_off(n); + std::mem::swap(&mut new, list); + new + } + + let reserved = inner( + &mut self.preprocessed.triplets.multiplication_triplets, + amount, + ); + + let party_fuel = { + let old = &mut self.preprocessed.for_sharing.party_fuel; + old.iter_mut() + .map(|tank| FuelTank { + party: tank.party, + shares: inner(&mut tank.shares, amount), + }) + .collect() + }; + let preprocessed = PreprocessedValues { + triplets: Triplets { + multiplication_triplets: reserved, + }, + for_sharing: PreShareTank { + party_fuel, + my_randomness: inner(&mut self.preprocessed.for_sharing.my_randomness, amount), + me: self.preprocessed.for_sharing.me, + }, + }; + Self { + opened_values: vec![], + params: self.params.clone(), + preprocessed, + } + } + + fn put_back(&mut self, mut other: Self) { + self.opened_values.append(&mut other.opened_values); + self.preprocessed + .triplets + .multiplication_triplets + .append(&mut other.preprocessed.triplets.multiplication_triplets); + self.preprocessed + .for_sharing + .my_randomness + .append(&mut other.preprocessed.for_sharing.my_randomness); + self.preprocessed + .for_sharing + .party_fuel + .iter_mut() + .zip(other.preprocessed.for_sharing.party_fuel) + .for_each(|(tank, mut old)| tank.shares.append(&mut old.shares)); + } +} + impl Error for PreProcError {} // ToDo: we should probably make getters for all the fields, and make them private, spdz needs to use the values, but not alter them. #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct PreprocessedValues { + // change to beaver module pub triplets: Triplets, - pub for_sharing: ForSharing, + + pub for_sharing: PreShareTank, } // TODO: Document this #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] -pub struct ForSharing { - pub rand_known_to_i: RandomKnownToPi, // consider boxed slices for the outer vec - pub rand_known_to_me: RandomKnownToMe, +pub struct PreShareTank { + /// Fuel per Party + pub party_fuel: Vec>, // consider boxed slices for the outer vec + pub my_randomness: Vec, + pub me: Id, +} + +impl PreShareTank { + pub fn empty(me: Id, party_size: usize) -> Self { + let party_fuel = (0..party_size).map(|id| FuelTank::empty(Id(id))).collect(); + Self { + party_fuel, + my_randomness: vec![], + me, + } + } + + pub fn get_fuel_vec_mut(&mut self, id: Id) -> &mut Vec> { + &mut self.party_fuel[id.0].shares + } + + pub fn get_fuel_mut(&mut self, id: Id) -> &mut FuelTank { + &mut self.party_fuel[id.0] + } + + pub fn get_own(&mut self) -> (&mut FuelTank, &mut Vec) { + (&mut self.party_fuel[self.me.0], &mut self.my_randomness) + } + + pub fn split( + &mut self, + ) -> ( + &mut FuelTank, + &mut Vec, + impl IntoIterator>, + ) { + let (head, tail) = self.party_fuel.split_at_mut(self.me.0); + let (my_fueltank, tail) = tail.split_first_mut().unwrap(); + let others = head.iter_mut().chain(tail); + debug_assert_eq!(self.me, my_fueltank.party); + + (my_fueltank, &mut self.my_randomness, others) + } +} + +impl PreShareTank { + pub fn bad_habits(&self) -> Vec>> { + self.party_fuel.iter().map(|f| f.shares.clone()).collect() + } } /// Multiplication triplet fuel tank #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct Triplets { - multiplication_triplets: Vec>, + pub(crate) multiplication_triplets: Vec>, } // TODO: Use beaver module @@ -66,27 +171,36 @@ impl Triplets { } } -#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] -pub struct MultiplicationTriple { - pub a: spdz::Share, - pub b: spdz::Share, - pub c: spdz::Share, -} +pub type MultiplicationTriple = beaver::BeaverTriple>; impl MultiplicationTriple { pub fn new(a: spdz::Share, b: spdz::Share, c: spdz::Share) -> Self { - MultiplicationTriple { a, b, c } + MultiplicationTriple { shares: (a, b, c) } } } #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] -pub struct RandomKnownToPi { - pub shares: Vec>>, +pub struct FuelTank { + pub party: Id, + pub shares: Vec>, } -#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] -pub struct RandomKnownToMe { - pub vals: Vec, +impl FuelTank { + pub fn empty(id: Id) -> Self { + Self { + party: id, + shares: Vec::new(), + } + } + + pub fn subtank(&mut self, take: usize) -> Self { + let len = self.shares.len(); + let shares = self.shares.drain(len - take..).collect(); + Self { + party: self.party, + shares, + } + } } pub struct SecretValues { @@ -95,7 +209,7 @@ pub struct SecretValues { pub fn write_context( files: &mut [File], - known_to_each: Vec, + known_to_each: &[usize], number_of_triplets: usize, _: F, ) -> Result<(), Box> { @@ -115,83 +229,94 @@ pub fn write_context( pub fn load_context( file: &mut File, -) -> SpdzContext { +) -> Result, bincode::Error> { // TODO: return Result instead. let buffered = std::io::BufReader::new(file); - bincode::deserialize_from(buffered).unwrap() + bincode::deserialize_from(buffered) } pub async fn load_context_async( file: &Path, -) -> SpdzContext { +) -> Result, bincode::Error> { let contents = tokio::fs::read(file).await.unwrap(); // TODO: return Result instead. - bincode::deserialize_from(&*contents).unwrap() + bincode::deserialize_from(&*contents) +} + +fn dealer_preshares( + mut rng: impl Rng, + per_party: &[usize], + num_of_parties: usize, +) -> (Vec, Vec>) { + let mac_keys: Vec = (0..num_of_parties).map(|_| F::random(&mut rng)).collect(); + let mac_key = mac_keys.iter().sum(); + + // Filling the context + // First with values used for easy sharing + let mut parties: Vec<_> = (0..num_of_parties) + .map(|id| PreShareTank::empty(Id(id), num_of_parties)) + .collect(); + for (me, &kte) in per_party.iter().enumerate() { + let r = Vector::from_vec(vec![F::random(&mut rng); kte]); + let mut r_mac = r.clone() * mac_key; + let mut ri_rest = r.clone(); + + // party_i + for (i, party) in parties[0..num_of_parties - 1].iter_mut().enumerate() { + let ri = Vector::from_vec(vec![F::random(&mut rng); kte]); + ri_rest -= &ri; + let r_mac_i = Vector::from_vec(vec![F::random(&mut rng); kte]); + r_mac -= &r_mac_i; + + let mut ri_share: Vec<_> = ri + .into_iter() + .zip(r_mac_i) + .map(|(val, mac)| spdz::Share { val, mac }) + .collect(); + party.party_fuel[me].shares.append(&mut ri_share); + if me == i { + let mut r = r.to_vec(); + party.my_randomness.append(&mut r); + } + } + let r2 = ri_rest; + let mut r2_share: Vec<_> = r2 + .into_iter() + .zip(r_mac) + .map(|(val, mac)| spdz::Share { val, mac }) + .collect(); + parties[num_of_parties - 1].party_fuel[me] + .shares + .append(&mut r2_share); + if me == num_of_parties - 1 { + let mut r = r.to_vec(); + parties[me].my_randomness.append(&mut r); + } + } + + (mac_keys, parties) } pub fn dealer_preproc( mut rng: impl rand::Rng, - known_to_each: Vec, + known_to_each: &[usize], number_of_triplets: usize, number_of_parties: usize, ) -> (Vec>, SecretValues) { // TODO: tjek that the arguments are consistent - let mac_keys: Vec = (0..number_of_parties) - .map(|_| F::random(&mut rng)) - .collect(); - let mut contexts: Vec> = (0..number_of_parties) + let (mac_keys, parties) = dealer_preshares(&mut rng, known_to_each, number_of_parties); + + // TODO: don't recalculate this + let mac_key = mac_keys.iter().sum(); + + let mut ctxs: Vec> = (0..number_of_parties) .map(|i| SpdzContext::empty(number_of_parties, mac_keys[i], Id(i))) .collect(); - let mac_key = mac_keys.into_iter().sum(); - // Filling the context - // First with values used for easy sharing - for (me, kte) in known_to_each.into_iter().enumerate() { - for _ in 0..kte { - let r = F::random(&mut rng); - let mut r_mac = r * mac_key; - let mut ri_rest = r; - for i in 0..number_of_parties - 1 { - let ri = F::random(&mut rng); - ri_rest -= ri; - let r_mac_i = F::random(&mut rng); - r_mac -= r_mac_i; - let ri_share = spdz::Share { - val: ri, - mac: r_mac_i, - }; - contexts[i].preprocessed.for_sharing.rand_known_to_i.shares[me].push(ri_share); - if me == i { - contexts[me] - .preprocessed - .for_sharing - .rand_known_to_me - .vals - .push(r); - } - } - let r2 = ri_rest; - //let r_mac_2 = r_mac; - let r2_share = spdz::Share { - val: r2, - mac: r_mac, - }; - contexts[number_of_parties - 1] - .preprocessed - .for_sharing - .rand_known_to_i - .shares[me] - .push(r2_share); - if me == number_of_parties - 1 { - contexts[me] - .preprocessed - .for_sharing - .rand_known_to_me - .vals - .push(r); - } - } + for (ctx, for_sharing) in ctxs.iter_mut().zip(parties.into_iter()) { + ctx.preprocessed.for_sharing = for_sharing } + // Now filling in triplets for _ in 0..number_of_triplets { @@ -233,7 +358,7 @@ pub fn dealer_preproc( }; let triplet = MultiplicationTriple::new(ai_share, bi_share, ci_share); - contexts[i] + ctxs[i] .preprocessed .triplets .multiplication_triplets @@ -244,7 +369,7 @@ pub fn dealer_preproc( let ci_share = spdz::Share { val: c, mac: c_mac }; let triplet = MultiplicationTriple::new(ai_share, bi_share, ci_share); - contexts[number_of_parties - 1] + ctxs[number_of_parties - 1] .preprocessed .triplets .multiplication_triplets @@ -253,7 +378,7 @@ pub fn dealer_preproc( // TODO: The secret values are only there for testing/ develompent purposes, consider removing it. let secret_values = SecretValues { mac_key }; - (contexts, secret_values) + (ctxs, secret_values) } impl SpdzContext { @@ -261,8 +386,8 @@ impl SpdzContext { generate_empty_context(number_of_parties, mac_key_share, who_am_i) } - pub fn from_file(mut file: File) -> Result { - Ok(load_context(&mut file)) + pub fn from_file(mut file: File) -> Result { + load_context(&mut file) } } @@ -271,18 +396,19 @@ fn generate_empty_context( mac_key_share: F, who_am_i: Id, ) -> SpdzContext { - let rand_known_to_i = RandomKnownToPi { - shares: vec![vec![]; number_of_parties], - }; - let rand_known_to_me = RandomKnownToMe { vals: vec![] }; + let rand_known_to_i = (0..number_of_parties) + .map(|id| FuelTank::empty(Id(id))) + .collect(); + let rand_known_to_me = vec![]; let triplets = Triplets { multiplication_triplets: vec![], }; let p_preprosvals = PreprocessedValues { triplets, - for_sharing: ForSharing { - rand_known_to_i, - rand_known_to_me, + for_sharing: PreShareTank { + party_fuel: rand_known_to_i, + my_randomness: rand_known_to_me, + me: who_am_i, }, }; SpdzContext { diff --git a/src/testing/mock.rs b/src/testing/mock.rs index 9665ba0..8e6072a 100644 --- a/src/testing/mock.rs +++ b/src/testing/mock.rs @@ -1,4 +1,4 @@ -use std::ops::{AddAssign, SubAssign}; +use std::ops::{AddAssign, MulAssign, SubAssign}; use itertools::Itertools; use serde::{de::DeserializeOwned, Deserialize, Serialize}; @@ -6,7 +6,7 @@ use serde::{de::DeserializeOwned, Deserialize, Serialize}; use crate::{ algebra::{field::Field, math::Vector}, net::Id, - schemes::{Shared, SharedMany}, + schemes::{Reserve, Shared, SharedMany}, }; #[derive(Debug, Clone, Copy, Serialize, Deserialize)] @@ -65,6 +65,12 @@ impl std::ops::Mul for Share { } } +impl MulAssign<&F> for Share { + fn mul_assign(&mut self, rhs: &F) { + self.value = self.value * *rhs; + } +} + impl Share { pub fn new_context(id: Id, total_parties: usize) -> Context { Context { @@ -80,6 +86,14 @@ pub struct Context { pub me: Id, } +impl Reserve for Context { + fn reserve(&mut self, _amount: usize) -> Self { + *self + } + + fn put_back(&mut self, _other: Self) {} +} + impl Context { pub fn parties(&self) -> std::ops::Range { 0..self.all_parties diff --git a/src/testing/mod.rs b/src/testing/mod.rs index 4f392a7..28a5695 100644 --- a/src/testing/mod.rs +++ b/src/testing/mod.rs @@ -7,12 +7,13 @@ use crate::{ protocols::beaver, vm::{Engine, Script}, }; +use futures::TryFutureExt; use rand::rngs::mock::StepRng; -use std::future::Future; +use std::{error::Error, future::Future}; use tokio::task::JoinError; -pub struct Cluster { - players: Vec, //players: tokio::task::JoinSet, +pub struct Cluster { + players: Vec, //players: tokio::task::JoinSet, args: Vec, } impl Cluster { @@ -24,7 +25,9 @@ impl Cluster { players, } } +} +impl Cluster<(), C> { /// Provide arguments of type `A` to the cluster as a list with each networked party. /// The arguments are to be provided as a list of size eqaul to the clister /// @@ -33,17 +36,17 @@ impl Cluster { /// use caring::testing::*; // party 1 party 2 /// // v--------v v--------v /// let cluster = Cluster::new(2).with_args([(1, "alice"), (2, "bob")]) - /// cluster.run_with_args(|net, (id, name)| async move { + /// cluster.run_with_args(|com, (id, name)| async move { /// println!("[{id}] hello from {name}"); /// }).await.unwrap(); /// /// ``` - pub fn with_args(self, args: impl Into>) -> Cluster { + pub fn with_args(self, args: impl Into>) -> Cluster { let args: Vec = args.into(); let m = args.len(); let n = self.players.len(); assert_eq!(m, n, "Cluster of size {n} requies {n} arguments, got {m}"); - Cluster { + Cluster:: { args, players: self.players, } @@ -59,15 +62,15 @@ impl Cluster { pub async fn run(self, prg: P) -> Result, JoinError> where T: Send + 'static, - P: Fn(InMemoryNetwork) -> F, + P: Fn(C) -> F, F: Future + Send + 'static, { self.run_with_args(|p, _| prg(p)).await } } -impl Cluster { - pub fn more_args(self, args: impl Into>) -> Cluster<(Arg, B)> { +impl Cluster { + pub fn more_args(self, args: impl Into>) -> Cluster<(Arg, B), C> { let args: Vec<_> = self.args.into_iter().zip(args.into()).collect(); Cluster { players: self.players, @@ -90,16 +93,30 @@ impl Cluster { pub async fn run_with_args(self, prg: P) -> Result, JoinError> where T: Send + 'static, - P: Fn(InMemoryNetwork, Arg) -> F, + P: Fn(C, Arg) -> F, F: Future + Send + 'static, { + let n = self.players.len(); + tracing::info!("Starting cluster with {n} players"); let futures: Vec<_> = self .players .into_iter() .zip(self.args.into_iter()) - .map(|(p, arg)| { + .enumerate() + .map(|(id, (p, arg))| { let fut = prg(p, arg); - tokio::spawn(fut) + use tracing::Instrument; + let span = tracing::info_span!("Player", id = id); + tokio::spawn(fut.instrument(span)).inspect_err(move |e| { + let reason = e.source(); + if e.is_panic() { + tracing::error!("Player {id} panic'ed: {e}, reason: {reason:?}"); + } else if e.is_cancelled() { + tracing::error!("Player {id} was cancelled: {e}, reason: {reason:?}"); + } else { + tracing::error!("Player {id} returned an error: {e}, reason: {reason:?}"); + } + }) }) .collect(); @@ -123,7 +140,7 @@ impl Cluster> { let mut fueltanks = beaver::BeaverTriple::fake_many(&context, shared_rng, 2000); let mut engine = Engine::<_, S, _>::new(context, network, private_rng); engine.add_fuel(&mut fueltanks[context.me.0]); - engine.execute(&script).await.unwrap_single() + engine.execute(&script).await.unwrap().unwrap_single() }) .await } diff --git a/src/vm/ast.rs b/src/vm/ast.rs new file mode 100644 index 0000000..15f0c1f --- /dev/null +++ b/src/vm/ast.rs @@ -0,0 +1,183 @@ +use crate::{ + net::Id, + vm::{ConstRef, Instruction}, +}; + +#[derive(Clone, Copy)] +pub struct ExpRef(u16); + +#[derive(Clone)] +pub enum Expression { + Share(ConstRef), + SymShare(ConstRef), + Recv(Id), + Open(ExpRef), + MulCon(ExpRef, ConstRef), + BinOp { + op: BinOp, + left: ExpRef, + right: ExpRef, + }, +} + +impl Expression { + pub fn translate(&self) -> Instruction { + match self { + Expression::Share(c) => Instruction::Share(*c), + Expression::SymShare(_) => todo!(), + Expression::Recv(id) => Instruction::Recv(*id), + Expression::Open(_) => Instruction::Recombine, + Expression::MulCon(_, c) => Instruction::MulCon(*c), + Expression::BinOp { + op, + left: _, + right: _, + } => match op { + BinOp::Add => Instruction::Add, + BinOp::Sub => Instruction::Sub, + BinOp::Mul => Instruction::Mul, + }, + } + } +} + +#[derive(Clone)] +pub enum BinOp { + Add, + Sub, + Mul, +} + +#[derive(Clone, Default)] +pub struct Ast { + // Consider a constant pool? + expressions: Vec, +} + +impl Ast { + pub fn parse_bytecode(insts: &[Instruction]) -> Self { + let mut expressions = Vec::with_capacity(insts.len()); + let mut stack = Vec::new(); + for (i, opcode) in insts.iter().enumerate() { + let exp = match opcode { + Instruction::Share(c) => { + stack.push(i); + Expression::Share(*c) + } + Instruction::SymShare(_) => { + todo!("Need to know party size") + } + Instruction::Recv(id) => { + stack.push(i); + Expression::Recv(*id) + } + Instruction::MulCon(c) => { + let exp_ref = ExpRef(stack.pop().unwrap() as u16); + Expression::MulCon(exp_ref, *c) + } + Instruction::RecvVec(_) => todo!("Handle vector operations better"), + Instruction::Recombine => { + let exp_ref = ExpRef(stack.pop().unwrap() as u16); + Expression::Open(exp_ref) + } + Instruction::Add => { + let right = ExpRef(stack.pop().unwrap() as u16); + let left = ExpRef(stack.pop().unwrap() as u16); + let op = BinOp::Add; + Expression::BinOp { op, left, right } + } + Instruction::Sub => { + let right = ExpRef(stack.pop().unwrap() as u16); + let left = ExpRef(stack.pop().unwrap() as u16); + let op = BinOp::Add; + Expression::BinOp { op, left, right } + } + Instruction::Mul => { + let right = ExpRef(stack.pop().unwrap() as u16); + let left = ExpRef(stack.pop().unwrap() as u16); + let op = BinOp::Add; + Expression::BinOp { op, left, right } + } + Instruction::Sum(_) => todo!("Need to know party size"), + }; + expressions.push(exp); + } + Self { expressions } + } + + fn sort(&mut self) { + self.expressions.sort_by_key(|exp| match exp { + Expression::Share(_) => -1, + Expression::SymShare(_) => -1, + Expression::Recv(_) => -1, + Expression::Open(exp) => exp.0 as i32, + Expression::MulCon(exp, _) => exp.0 as i32, + Expression::BinOp { op: _, left, right } => { + let a = left.0 as i32; + let b = right.0 as i32; + a.max(b) + } + }) + } + + pub fn to_bytecode_fast(&self) -> Vec { + // Assume epxressions are in order. + self.traverse_fast().map(|e| e.translate()).collect() + } + + pub fn to_bytecode_safe(&self) -> Vec { + self.traverse().map(|e| e.translate()).collect() + } + + pub fn traverse(&self) -> impl Iterator { + let mut stack = Vec::new(); + let mut to_visit = Vec::new(); + // Consider what the last expression might be. + let last = ExpRef((self.expressions.len() - 1) as u16); + stack.push(last); + while let Some(exp) = stack.pop() { + to_visit.push(exp); + let exp = &self.expressions[exp.0 as usize]; + match exp { + Expression::Share(_) | Expression::SymShare(_) | Expression::Recv(_) => {} + Expression::Open(exp) => { + stack.push(*exp); + } + Expression::MulCon(exp, _) => { + stack.push(*exp); + } + Expression::BinOp { op: _, left, right } => { + // TODO: Order + stack.push(*left); + stack.push(*right); + } + }; + } + to_visit + .into_iter() + .rev() + .map(|i| &self.expressions[i.0 as usize]) + } + + pub fn traverse_fast(&self) -> impl Iterator { + // Assume they are in order. + self.expressions.iter() + } +} + +#[cfg(test)] +mod test { + use crate::vm::{ast::Ast, Instruction}; + + fn check_identity(bytecode: &[Instruction]) { + let ast = Ast::parse_bytecode(bytecode); + let translated = ast.to_bytecode_safe(); + assert_eq!(bytecode, translated.as_slice()) + } + + fn check_identity_fast(bytecode: &[Instruction]) { + let ast = Ast::parse_bytecode(bytecode); + let translated = ast.to_bytecode_safe(); + assert_eq!(bytecode, translated.as_slice()) + } +} diff --git a/src/vm/mod.rs b/src/vm/mod.rs index d7181d4..f3f9b47 100644 --- a/src/vm/mod.rs +++ b/src/vm/mod.rs @@ -1,20 +1,25 @@ +mod ast; pub mod parsing; -use ff::Field; +use std::{collections::BTreeMap, error::Error, fmt::Display}; + +use ff::{Field, PrimeField}; use itertools::{Either, Itertools}; use rand::RngCore; +use serde::{de::DeserializeOwned, Deserialize, Serialize}; +use thiserror::Error; use crate::{ - algebra::math::Vector, + algebra::{math::Vector, Length}, net::{agency::Broadcast, connection::TcpConnection, network::Network, Id, SplitChannel}, - protocols::beaver::{beaver_multiply, BeaverTriple}, - schemes::interactive::{InteractiveShared, InteractiveSharedMany}, + protocols::beaver::{beaver_multiply, beaver_multiply_vector, BeaverTriple}, + schemes::{interactive::InteractiveSharedMany, spdz}, }; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub enum Value { Single(F), - Vector(Vector), + Vectorized(Vector), } impl Value { @@ -27,7 +32,7 @@ impl Value { pub fn unwrap_vector(self) -> Vector { match self { - Value::Vector(v) => v, + Value::Vectorized(v) => v, _ => panic!("Was single and not a vector!"), } } @@ -35,14 +40,14 @@ impl Value { pub fn map(self, func: impl Fn(F) -> U) -> Value { match self { Value::Single(a) => Value::Single(func(a)), - Value::Vector(a) => Value::Vector(a.into_iter().map(func).collect()), + Value::Vectorized(a) => Value::Vectorized(a.into_iter().map(func).collect()), } } pub fn to_vec(self) -> Vec { match self { Value::Single(s) => vec![s], - Value::Vector(v) => v.into(), + Value::Vectorized(v) => v.into(), } } } @@ -54,7 +59,7 @@ impl From for Value { } impl From> for Value { fn from(value: Vector) -> Self { - Value::Vector(value) + Value::Vectorized(value) } } @@ -65,7 +70,7 @@ impl Value { { match self { Value::Single(v) => Value::Single(v.into()), - Value::Vector(v) => Value::Vector(v.into_iter().map(|v| v.into()).collect()), + Value::Vectorized(v) => Value::Vectorized(v.into_iter().map(|v| v.into()).collect()), } } @@ -75,22 +80,22 @@ impl Value { { match self { Value::Single(v) => Ok(Value::Single(v.try_into()?)), - Value::Vector(v) => { + Value::Vectorized(v) => { let bs: Vector = v.into_iter().map(|v| v.try_into()).try_collect()?; - Ok(Value::Vector(bs)) + Ok(Value::Vectorized(bs)) } } } } -#[derive(Debug, Clone, Copy)] -pub struct Const(u16); +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +pub struct ConstRef(u16); -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] pub enum Instruction { - Share(Const), - SymShare(Const), - MulCon(Const), + Share(ConstRef), + SymShare(ConstRef), + MulCon(ConstRef), Recv(Id), RecvVec(Id), Recombine, @@ -100,6 +105,23 @@ pub enum Instruction { Sum(usize), } +impl Display for Instruction { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Instruction::Share(const_ref) => write!(f, "share ${const_ref:?}"), + Instruction::SymShare(const_ref) => write!(f, "symshare ${const_ref:?}"), + Instruction::MulCon(const_ref) => write!(f, "mul ${const_ref:?}"), + Instruction::Recv(id) => write!(f, "recv #{id:?}"), + Instruction::RecvVec(id) => write!(f, "recv_vec #{id:?}"), + Instruction::Recombine => write!(f, "open"), + Instruction::Add => write!(f, "add"), + Instruction::Sub => write!(f, "add"), + Instruction::Mul => write!(f, "add"), + Instruction::Sum(n) => write!(f, "sum {n}"), + } + } +} + #[derive(Clone, Debug)] enum SharedValue { Single(S), @@ -111,11 +133,112 @@ pub struct Script { instructions: Vec, } +impl Display for Script { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let n = self.constants.len(); + writeln!(f, "Constant Pool Sized {n}")?; + writeln!(f, "Program:")?; + for inst in &self.instructions { + writeln!(f, "\t{inst}")?; + } + Ok(()) + } +} + +impl Script { + pub fn mults(&self, parties: usize) -> usize { + self.count_mult_shared(parties) + .0 + .into_iter() + .map(|(size, amount)| size * amount) + .sum() + } + + pub fn shared(&self, parties: usize) -> usize { + self.count_mult_shared(parties).1 + } + + fn get_constant(&self, addr: ConstRef) -> &Value { + self.constants.get(addr.0 as usize).unwrap() + } + + /// Provide the number of multiplications (per vector size) and shares + fn count_mult_shared(&self, parties: usize) -> (BTreeMap, usize) { + let mut mults = BTreeMap::new(); + let mut shared = 0; + let mut stack = Vec::new(); + for inst in &self.instructions { + match inst { + Instruction::Share(addr) => match self.get_constant(*addr) { + Value::Single(_) => { + stack.push(1usize); + shared += 1; + } + Value::Vectorized(v) => { + stack.push(v.len()); + shared += v.len(); + } + }, + Instruction::SymShare(addr) => match self.get_constant(*addr) { + Value::Single(_) => { + stack.append(&mut vec![1usize; parties]); + shared += parties; + } + Value::Vectorized(v) => { + shared += v.len() * parties; + stack.append(&mut vec![v.len(); parties]) + } + }, + Instruction::MulCon(addr) => { + stack.pop(); + match self.get_constant(*addr) { + Value::Single(_) => stack.push(1usize), + Value::Vectorized(v) => stack.push(v.len()), + } + } + Instruction::Recv(_) => { + stack.push(1); + shared += 1; + } + Instruction::RecvVec(_) => { + stack.push(0); + shared += 1; + } + Instruction::Recombine => { + stack.pop(); + } + Instruction::Add | Instruction::Sub => { + let a = stack.pop().unwrap(); + let b = stack.pop().unwrap(); + if a == 0 { + stack.push(b) + } else { + stack.push(a) + } + } + Instruction::Mul => { + let size = stack.pop().unwrap(); + mults + .entry(size) + .and_modify(|amount: &mut usize| *amount += 1); + } + Instruction::Sum(n) => { + let n = if *n == 0 { parties } else { *n }; + for _ in 0..(n - 1) { + stack.pop(); + } + } + } + } + (mults, shared) + } +} + #[derive(Debug)] -pub struct Engine { +pub struct Engine { network: Network, context: S::Context, - fueltank: Vec>, + fueltank: FuelTank, rng: R, } @@ -184,6 +307,76 @@ impl Stack { } } +struct FuelTank { + pub mult_triples: Vec>, +} + +impl FuelTank +where + S: InteractiveSharedMany, +{ + pub fn single_mult(&mut self) -> Option> { + self.mult_triples.pop() + } + + pub fn vector_mult(&mut self, size: usize) -> Option> { + if self.mult_triples.len() < size { + return None; + } + let iter = self.mult_triples.drain(..size); + Some(BeaverTriple::vectorized(iter)) + } +} + +impl std::fmt::Debug for FuelTank +where + S: InteractiveSharedMany, +{ + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("FuelTank") + .field("mult_triples", &self.mult_triples.len()) + .finish() + } +} + +impl Default for FuelTank +where + S: InteractiveSharedMany, +{ + fn default() -> Self { + Self { + mult_triples: vec![], + } + } +} + +#[derive(Debug, Error)] +#[error("Error during Execution: {reason} - at instruction {line}")] +pub struct ExecutionError { + // We currently do not want to virally propagate all of S::Error everywhere. + // In the future, we might neuter S::Error along with the associated error types in + // `caring::net`. + reason: Box, + line: usize, +} + +#[derive(Debug, Error)] +enum RuntimeError { + // Allow to easily wrap the Shared::Error + #[error(transparent)] + Base(#[from] E), + + #[error("No elemented left on stack")] + EmptyStack(), + + #[error("No result on result-stack")] + NoResult(), + + // Might detail this more out. + #[error("Out of Fuel (Mults): {need} needed, had {in_reserve}")] + MissingFuel { need: usize, in_reserve: usize }, // Might add more here, such as communications errors et al. +} + impl Engine where C: SplitChannel, @@ -195,7 +388,7 @@ where Self { network, context, - fueltank: vec![], + fueltank: FuelTank::default(), rng, } } @@ -209,23 +402,49 @@ where } pub fn add_fuel(&mut self, fuel: &mut Vec>) { - self.fueltank.append(fuel); + self.fueltank.mult_triples.append(fuel); } // TODO: Superscalar execution when awaiting. - pub async fn execute(&mut self, script: &Script) -> Value { + pub async fn execute(&mut self, script: &Script) -> Result, ExecutionError> { let mut stack = Stack::new(); let mut results: Vec> = vec![]; let constants = &script.constants; - for opcode in script.instructions.iter() { + let n = script.instructions.len(); + let m = constants.len(); + let i = self.network.id(); + let f = self.fueltank.mult_triples.len(); + tracing::info!( + "Starting execution of {n} instructions with {m} contants as player {i} with {f} fuel" + ); + for (i, c) in constants.iter().enumerate() { + tracing::debug!("Constant[{i}]: {c:?}"); + } + + for (i, opcode) in script.instructions.iter().enumerate() { + tracing::trace!("Executing opcode: {opcode}"); self.step(&mut stack, &mut results, constants, opcode) .await - .unwrap(); + .map_err(|e| ExecutionError { + reason: Box::new(e), + line: i, + })?; + } + + for (i, c) in results.iter().enumerate() { + tracing::debug!("Results[{i}]: {c:?}"); } - results.pop().unwrap() + // TODO: Handle multiple outputs + results.pop().ok_or_else(|| { + let reason = Box::new(RuntimeError::::NoResult()).into(); + ExecutionError { + reason, + line: script.instructions.len() + 1, + } + }) } async fn step( @@ -234,34 +453,43 @@ where results: &mut Vec>, constants: &[Value], opcode: &Instruction, - ) -> Result<(), S::Error> { + ) -> Result<(), RuntimeError> { let ctx = &mut self.context; let mut coms = &mut self.network; let mut rng = &mut self.rng; let fueltank = &mut self.fueltank; + let get_constant = |addr: &ConstRef| &constants[addr.0 as usize]; + + // NOTE: Currently the engine is implemented with allowing mixing scalar and multiple + // arbitrary vector (sizes). While convenient, this allows for runtime errors as + // the operations between these different types is currently unspecified, + // resulting in a panic. One should consider if we should have multiple different engines, + // for each type, multiple stacks (for each type) or accept the current design. + // The program itself can be validated beforehand, as all input sizes are known, + // with exception of SymShare, which is evil anyway. match opcode { Instruction::Share(addr) => { - let f = &constants[addr.0 as usize]; + let f = get_constant(addr); match f { Value::Single(f) => { let share = S::share(ctx, *f, &mut rng, &mut coms).await?; stack.push_single(share) } - Value::Vector(fs) => { + Value::Vectorized(fs) => { let share = S::share_many(ctx, fs, &mut rng, &mut coms).await?; stack.push_vector(share) } } } Instruction::SymShare(addr) => { - let f = &constants[addr.0 as usize]; + let f = get_constant(addr); match f { Value::Single(f) => { let shares = S::symmetric_share(ctx, *f, &mut rng, &mut coms).await?; let shares = shares.into_iter().map(|s| SharedValue::Single(s)); stack.stack.extend(shares) // dirty hack } - Value::Vector(f) => { + Value::Vectorized(f) => { let shares = S::symmetric_share_many(ctx, f, &mut rng, &mut coms).await?; let shares = shares.into_iter().map(|s| SharedValue::Vector(s)); stack.stack.extend(shares) // dirty hack @@ -284,7 +512,7 @@ where } SharedValue::Vector(share) => { let f = S::recombine_many(ctx, share, &mut coms).await?; - results.push(Value::Vector(f)); + results.push(Value::Vectorized(f)); } }; } @@ -307,16 +535,14 @@ where } } Instruction::MulCon(addr) => { - let constant = &constants[addr.0 as usize]; - match (stack.pop(), constant) { - (SharedValue::Single(a), Value::Single(constant)) => { - stack.push_single(a * *constant) - } - (SharedValue::Vector(_a), Value::Vector(_constant)) => { + let con = get_constant(addr); + match (stack.pop(), con) { + (SharedValue::Single(a), Value::Single(con)) => stack.push_single(a * *con), + (SharedValue::Vector(_a), Value::Vectorized(_con)) => { todo!("vector mult") //stack.push_vector(a * &constant) } - (SharedValue::Single(_), Value::Vector(_)) => todo!(), + (SharedValue::Single(_), Value::Vectorized(_)) => todo!(), (SharedValue::Vector(_), Value::Single(_)) => todo!(), } } @@ -325,17 +551,34 @@ where let y = stack.pop(); match (x, y) { (SharedValue::Single(x), SharedValue::Single(y)) => { - let triple = fueltank.pop().unwrap(); + let triple = + fueltank + .single_mult() + .ok_or_else(|| RuntimeError::MissingFuel { + need: 1, + in_reserve: self.fueltank.mult_triples.len(), + })?; let z = beaver_multiply(ctx, x, y, triple, &mut coms).await?; stack.push_single(z) } - (SharedValue::Vector(_x), SharedValue::Vector(_y)) => { - todo!() + (SharedValue::Vector(x), SharedValue::Vector(y)) => { + let size = x.len(); + let triple = fueltank.vector_mult(size).ok_or_else(|| { + RuntimeError::MissingFuel { + need: size, + in_reserve: self.fueltank.mult_triples.len(), + } + })?; + let z: S::VectorShare = + beaver_multiply_vector::(ctx, &x, &y, triple, &mut coms).await?; + stack.push_vector(z); } (SharedValue::Vector(_), SharedValue::Single(_y)) => { - todo!() + todo!("Allow for vector x scalar multiplication") + } + (SharedValue::Single(_), SharedValue::Vector(_)) => { + todo!("Allow for vector x scalar multiplication") } - (SharedValue::Single(_), SharedValue::Vector(_)) => todo!(), }; } Instruction::Sum(size) => { @@ -370,7 +613,24 @@ where } } -impl Engine { +impl Engine, R> +where + C: SplitChannel, + F: PrimeField + Serialize + DeserializeOwned, +{ + pub fn load_context(&mut self) { + let ctx = &mut self.context; + self.fueltank + .mult_triples + .append(&mut ctx.preprocessed.triplets.multiplication_triplets); + + let fuel = self.fueltank.mult_triples.len(); + tracing::info!("Loading {fuel} fuel from context"); + } +} + +impl Engine { + /// Gracefull shutdown the internal network pub async fn shutdown(self) -> Result<(), std::io::Error> { self.network.shutdown().await } @@ -384,7 +644,7 @@ mod tests { algebra::{self, element::Element32}, net::{agency::Broadcast, connection::DuplexConnection, network::InMemoryNetwork, Id}, testing::{self, mock}, - vm::{Const, Engine, Instruction, Value}, + vm::{ConstRef, Engine, Instruction, Value}, }; pub fn dumb_engine( @@ -401,7 +661,7 @@ mod tests { Engine { network, context, - fueltank: vec![], + fueltank: super::FuelTank::default(), rng, } } @@ -417,12 +677,17 @@ mod tests { let script = crate::vm::Script { constants: vec![Value::Single(val)], instructions: vec![ - SymShare(Const(0)), // add two to the stack. + SymShare(ConstRef(0)), // add two to the stack. Add, Recombine, ], }; - let res: u32 = engine.execute(&script).await.unwrap_single().into(); + let res: u32 = engine + .execute(&script) + .await + .unwrap() + .unwrap_single() + .into(); engine.network.shutdown().await.unwrap(); res }) @@ -439,27 +704,32 @@ mod tests { let a = crate::vm::Script { constants: vec![Value::Single(a)], instructions: vec![ - Share(Const(0)), // +1 - Recv(Id(1)), // +1 - Add, // -1 - Recombine, // -1 + Share(ConstRef(0)), // +1 + Recv(Id(1)), // +1 + Add, // -1 + Recombine, // -1 ], }; let b = Element32::from(57u32); let b = crate::vm::Script { constants: vec![Value::Single(b)], instructions: vec![ - Recv(Id(0)), // +1 - Share(Const(0)), // +1 - Add, // -1 - Recombine, // -1 + Recv(Id(0)), // +1 + Share(ConstRef(0)), // +1 + Add, // -1 + Recombine, // -1 ], }; let results = testing::Cluster::new(2) .with_args([a, b]) .run_with_args(|net, script| async move { let mut engine = dumb_engine(net); - let res: u32 = engine.execute(&script).await.unwrap_single().into(); + let res: u32 = engine + .execute(&script) + .await + .unwrap() + .unwrap_single() + .into(); engine.network.shutdown().await.unwrap(); res }) diff --git a/src/vm/parsing.rs b/src/vm/parsing.rs index 709a2a0..d59f634 100644 --- a/src/vm/parsing.rs +++ b/src/vm/parsing.rs @@ -9,7 +9,7 @@ use std::{ use crate::{ algebra::math::Vector, net::Id, - vm::{Const, Instruction, Script, Value}, + vm::{ConstRef, Instruction, Script, Value}, }; /// An expression stack @@ -44,9 +44,9 @@ impl Exp { } } - fn append_constant(&mut self, value: impl Into>) -> Const { + fn append_constant(&mut self, value: impl Into>) -> ConstRef { self.constants.push(value.into()); - Const(self.constants.len() as u16 - 1) + ConstRef(self.constants.len() as u16 - 1) } fn constant_op(value: impl Into>, opcode: Instruction) -> Self { @@ -67,7 +67,7 @@ impl Exp { // This is slighty cursed. pub fn symmetric_share_vec(secret: impl Into>) -> ExpList { ExpList { - constant: Value::Vector(secret.into()), + constant: Value::Vectorized(secret.into()), } } @@ -75,14 +75,14 @@ impl Exp { /// /// * `secret`: value to secret share pub fn share(secret: impl Into) -> Self { - Self::constant_op(secret.into(), Instruction::Share(Const(0))) + Self::constant_op(secret.into(), Instruction::Share(ConstRef(0))) } /// Secret share a vector /// /// * `secret`: vector to secret share pub fn share_vec(secret: impl Into>) -> Self { - Self::constant_op(secret.into(), Instruction::Share(Const(0))) + Self::constant_op(secret.into(), Instruction::Share(ConstRef(0))) } /// Receive are share from a given party `id` @@ -201,7 +201,7 @@ impl ExpList { pub fn concrete(self, own: usize, size: usize) -> Vec> { let mut me = Some(Exp { constants: vec![self.constant], - instructions: vec![Instruction::SymShare(Const(0))], + instructions: vec![Instruction::SymShare(ConstRef(0))], }); (0..size) .map(|id| { @@ -218,7 +218,7 @@ impl ExpList { use Instruction as I; Exp { constants: vec![self.constant], - instructions: vec![I::SymShare(Const(0)), I::Sum(0)], + instructions: vec![I::SymShare(ConstRef(0)), I::Sum(0)], } } } diff --git a/wecare/Cargo.lock b/wecare/Cargo.lock index 8e789a5..074fe2a 100644 --- a/wecare/Cargo.lock +++ b/wecare/Cargo.lock @@ -15,30 +15,18 @@ dependencies = [ [[package]] name = "addr2line" -version = "0.22.0" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375" 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.8.11" +name = "adler2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" -dependencies = [ - "cfg-if", - "once_cell", - "version_check", - "zerocopy", -] +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" [[package]] name = "aho-corasick" @@ -50,10 +38,19 @@ dependencies = [ ] [[package]] -name = "allocator-api2" -version = "0.2.18" +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] [[package]] name = "anes" @@ -61,6 +58,15 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + [[package]] name = "anstyle" version = "1.0.8" @@ -91,7 +97,7 @@ checksum = "affbba0d438add06462a0371997575927bc05052f7ec486e7a4ca405c956c3d7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -113,18 +119,18 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] name = "async-trait" -version = "0.1.81" +version = "0.1.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" +checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -141,17 +147,17 @@ checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973" [[package]] name = "backtrace" -version = "0.3.73" +version = "0.3.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" dependencies = [ "addr2line", - "cc", "cfg-if", "libc", "miniz_oxide", "object", "rustc-demangle", + "windows-targets 0.52.6", ] [[package]] @@ -198,9 +204,9 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytemuck" -version = "1.17.0" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fd4c6dcc3b0aea2f5c0b4b82c2b15fe39ddbc76041a310848f4706edf76bb31" +checksum = "94bbb0ad554ad961ddc5da507a12a29b14e4ae5bda06b19f575a3e6079d2e2ae" [[package]] name = "byteorder" @@ -210,9 +216,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.7.1" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" [[package]] name = "caring" @@ -221,11 +227,9 @@ dependencies = [ "async-backtrace", "async-trait", "bincode", - "castaway", "derive_more", "digest", "ff", - "fixed", "futures", "futures-concurrency", "group", @@ -240,6 +244,7 @@ dependencies = [ "tokio", "tokio-util", "tracing", + "tracing-serde", ] [[package]] @@ -248,20 +253,11 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" -[[package]] -name = "castaway" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0abae9be0aaf9ea96a3b1b8b1b55c602ca751eba1b1500220cea4ecbafe7c0d5" -dependencies = [ - "rustversion", -] - [[package]] name = "cc" -version = "1.1.14" +version = "1.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d2eb3cd3d1bf4529e31c215ee6f93ec5a3d536d9f578f93d9d33ee19562932" +checksum = "07b1695e2c7e8fc85310cde85aeaab7e3097f593c91d209d3f9df76c928100f0" dependencies = [ "shlex", ] @@ -272,6 +268,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-targets 0.52.6", +] + [[package]] name = "ciborium" version = "0.2.2" @@ -301,18 +311,18 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.16" +version = "4.5.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed6719fffa43d0d87e5fd8caeab59be1554fb028cd30edc88fc4369b17971019" +checksum = "3e5a21b8495e732f1b3c364c9949b201ca7bae518c502c80256c96ad79eaf6ac" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.5.15" +version = "4.5.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "216aec2b177652e3846684cbfe25c9964d18ec45234f0f5da5157b207ed1aab6" +checksum = "8cf2dd12af7a047ad9d6da2b6b249759a22a7abc0f474c1dae1777afa4b21a73" dependencies = [ "anstyle", "clap_lex", @@ -330,11 +340,17 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "cpufeatures" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51e852e6dc9a5bed1fae92dd2375037bf2b768725bf3be87811edee3249d09ad" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" dependencies = [ "libc", ] @@ -442,7 +458,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -468,14 +484,14 @@ dependencies = [ "proc-macro2", "quote", "rustc_version", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] name = "diatomic-waker" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af873b6853650fb206431c52fa7bbf6917146b70a8a9979d6d141f5d5394086b" +checksum = "ab03c107fafeb3ee9f5925686dbb7a73bc76e3932abb0d2b365cb64b169cf04c" [[package]] name = "digest" @@ -493,18 +509,6 @@ version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" -[[package]] -name = "enum_dispatch" -version = "0.3.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa18ce2bc66555b3218614519ac839ddb759a7d6720732f979ef8d13be147ecd" -dependencies = [ - "once_cell", - "proc-macro2", - "quote", - "syn 2.0.76", -] - [[package]] name = "errno" version = "0.3.9" @@ -679,7 +683,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -748,9 +752,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.29.0" +version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" [[package]] name = "group" @@ -778,10 +782,6 @@ name = "hashbrown" version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" -dependencies = [ - "ahash", - "allocator-api2", -] [[package]] name = "hermit-abi" @@ -795,6 +795,29 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" +[[package]] +name = "iana-time-zone" +version = "0.1.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "instant" version = "0.1.13" @@ -912,11 +935,11 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "miniz_oxide" -version = "0.7.4" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" dependencies = [ - "adler", + "adler2", ] [[package]] @@ -972,9 +995,9 @@ dependencies = [ [[package]] name = "object" -version = "0.36.3" +version = "0.36.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27b64972346851a39438c60b341ebc01bba47464ae329e55cf343eb93964efd9" +checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" dependencies = [ "memchr", ] @@ -999,9 +1022,9 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "parking" -version = "2.2.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" [[package]] name = "parking_lot" @@ -1043,7 +1066,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -1060,9 +1083,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "plotters" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a15b6eccb8484002195a3e44fe65a4ce8e93a625797a063735536fd59cb01cf3" +checksum = "5aeb6f403d7a4911efb1e33402027fc44f29b5bf6def3effcc22d7bb75f2b747" dependencies = [ "num-traits", "plotters-backend", @@ -1073,15 +1096,15 @@ dependencies = [ [[package]] name = "plotters-backend" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "414cec62c6634ae900ea1c56128dfe87cf63e7caece0852ec76aba307cebadb7" +checksum = "df42e13c12958a16b3f7f4386b9ab1f3e7933914ecea48da7139435263a4172a" [[package]] name = "plotters-svg" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81b30686a7d9c3e010b84284bdd26a29f2138574f52f5eb6f794fc0ad924e705" +checksum = "51bae2ac328883f7acdfea3d66a7c35751187f870bc81f94563733a154d7a670" dependencies = [ "plotters-backend", ] @@ -1171,9 +1194,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.3" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" +checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" dependencies = [ "bitflags", ] @@ -1236,18 +1259,18 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustc_version" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" dependencies = [ "semver", ] [[package]] name = "rustix" -version = "0.38.34" +version = "0.38.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" dependencies = [ "bitflags", "errno", @@ -1297,29 +1320,29 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.209" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.209" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] name = "serde_json" -version = "1.0.127" +version = "1.0.128" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" dependencies = [ "itoa", "memchr", @@ -1401,9 +1424,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.76" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578e081a14e0cefc3279b0472138c513f37b41a08d5a3cca9b6e4e8ceb6cd525" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -1446,7 +1469,7 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -1471,9 +1494,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.39.3" +version = "1.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9babc99b9923bfa4804bd74722ff02c0381021eafa4db9949217e3be8e84fff5" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" dependencies = [ "backtrace", "bytes", @@ -1495,14 +1518,14 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] name = "tokio-stream" -version = "0.1.15" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" dependencies = [ "futures-core", "pin-project-lite", @@ -1524,9 +1547,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.11" +version = "0.7.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" dependencies = [ "bytes", "futures-core", @@ -1558,7 +1581,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -1571,6 +1594,23 @@ dependencies = [ "valuable", ] +[[package]] +name = "tracing-forest" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee40835db14ddd1e3ba414292272eddde9dad04d3d4b65509656414d1c42592f" +dependencies = [ + "ansi_term", + "chrono", + "serde", + "smallvec", + "thiserror", + "tokio", + "tracing", + "tracing-subscriber", + "uuid", +] + [[package]] name = "tracing-log" version = "0.2.0" @@ -1582,6 +1622,16 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "tracing-serde" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1" +dependencies = [ + "serde", + "tracing-core", +] + [[package]] name = "tracing-subscriber" version = "0.3.18" @@ -1608,9 +1658,19 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "uuid" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314" +dependencies = [ + "getrandom", + "serde", +] [[package]] name = "valuable" @@ -1668,7 +1728,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", "wasm-bindgen-shared", ] @@ -1690,7 +1750,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1716,16 +1776,16 @@ name = "wecare" version = "0.1.0" dependencies = [ "caring", - "castaway", "criterion", "curve25519-dalek", - "enum_dispatch", "ff", "fixed", "rand", "tempfile", "tokio", "tokio-test", + "tracing", + "tracing-forest", ] [[package]] @@ -1768,6 +1828,15 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-sys" version = "0.52.0" @@ -1934,7 +2003,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] diff --git a/wecare/Cargo.toml b/wecare/Cargo.toml index 1aa21ef..5b5ec65 100644 --- a/wecare/Cargo.toml +++ b/wecare/Cargo.toml @@ -11,11 +11,11 @@ tokio = { version = "1.33.0", features = ["full"] } curve25519-dalek = { version = "4.1.3", features = ["group", "serde"] } rand = "0.8.5" fixed = "2.0.0-alpha.28.0" -enum_dispatch = "0.3.13" ff = "0.13.0" -castaway = "0.2.3" +tracing = "0.1.40" [dev-dependencies] +tracing-forest = { version = "0.1.6", features = ["full"] } caring = { path = "..", features = ["test"]} tokio-test = "0.4.4" criterion = "0.5.1" diff --git a/wecare/benches/shamir-25519.rs b/wecare/benches/shamir-25519.rs index 586eb9a..19c6765 100644 --- a/wecare/benches/shamir-25519.rs +++ b/wecare/benches/shamir-25519.rs @@ -19,6 +19,7 @@ fn build_shamir_engines() -> (blocking::Engine, blocking::Engine) { .connect_blocking() .unwrap() .build() + .unwrap() }); let e1 = scope.spawn(|| { thread::sleep(Duration::from_millis(200)); @@ -31,6 +32,7 @@ fn build_shamir_engines() -> (blocking::Engine, blocking::Engine) { .connect_blocking() .unwrap() .build() + .unwrap() }); (e1.join().unwrap(), e2.join().unwrap()) }); diff --git a/wecare/benches/spdz-25519.rs b/wecare/benches/spdz-25519.rs index 37353c1..bfd5944 100644 --- a/wecare/benches/spdz-25519.rs +++ b/wecare/benches/spdz-25519.rs @@ -14,7 +14,7 @@ fn precompute(n: usize) -> (File, File) { let ctx1 = tempfile::tempfile().unwrap(); let ctx2 = tempfile::tempfile().unwrap(); let mut files = [ctx1, ctx2]; - do_preproc(&mut files, &[n, n], false); + do_preproc(&mut files, &[n, n], 0, false).unwrap(); let [mut ctx1, mut ctx2] = files; ctx1.rewind().unwrap(); ctx2.rewind().unwrap(); @@ -23,7 +23,7 @@ fn precompute(n: usize) -> (File, File) { } fn build_spdz_engines() -> (blocking::Engine, blocking::Engine) { - let (mut ctx1, mut ctx2) = precompute(10000000); + let (ctx1, ctx2) = precompute(10000000); let clock = time::Instant::now(); print!("Setting up engines..."); let _ = std::io::stdout().flush(); @@ -39,6 +39,7 @@ fn build_spdz_engines() -> (blocking::Engine, blocking::Engine) { .connect_blocking() .unwrap() .build() + .unwrap() }); let e1 = scope.spawn(|| { thread::sleep(Duration::from_millis(200)); @@ -52,6 +53,7 @@ fn build_spdz_engines() -> (blocking::Engine, blocking::Engine) { .connect_blocking() .unwrap() .build() + .unwrap() }); (e1.join().unwrap(), e2.join().unwrap()) }); diff --git a/wecare/src/lib.rs b/wecare/src/lib.rs index c16f4a4..b799176 100644 --- a/wecare/src/lib.rs +++ b/wecare/src/lib.rs @@ -1,5 +1,3 @@ -#![feature(async_closure)] - pub mod vm; use caring::{ @@ -15,7 +13,7 @@ use caring::{ use curve25519_dalek::RistrettoPoint; use fixed::FixedI32; use rand::{thread_rng, SeedableRng}; -use std::{fs::File, net::SocketAddr, time::Duration}; +use std::{error::Error, fs::File, net::SocketAddr, time::Duration}; use tokio::runtime::Runtime; pub trait Mapping { @@ -127,33 +125,37 @@ pub type SpdzEngine32 = AdderEngine>; pub type ShamirEngine32 = AdderEngine>; #[derive(Debug)] -pub struct MpcError(pub &'static str); +pub struct MpcError(pub String); impl std::fmt::Display for MpcError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let msg = self.0; + let msg = &self.0; write!(f, "Bad thing happened: {msg}") } } impl std::error::Error for MpcError {} -pub fn do_preproc(files: &mut [File], number_of_shares: &[usize], use_32: bool) { - assert_eq!(files.len(), number_of_shares.len()); - let known_to_each = vec![number_of_shares[0], number_of_shares[1]]; - let number_of_triplets = 0; +pub fn do_preproc( + files: &mut [File], + num_preshares: &[usize], + num_triplets: usize, + use_32: bool, +) -> Result<(), Box> { + assert_eq!(files.len(), num_preshares.len()); if use_32 { let num = S32::from_f64(0.0); - preprocessing::write_context(files, known_to_each, number_of_triplets, num).unwrap(); + preprocessing::write_context(files, num_preshares, num_triplets, num) } else { let num = S25519::from_f64(0.0); - preprocessing::write_context(files, known_to_each, number_of_triplets, num).unwrap(); + preprocessing::write_context(files, num_preshares, num_triplets, num) } } pub type Engine = generic::AdderEngine; mod generic { + use super::*; pub enum AdderEngine { @@ -174,25 +176,29 @@ mod generic { impl<'a> EngineBuilder<'a> { pub fn build_spdz(self) -> Result { - let (network, runtime) = self.connect_network()?; + let (mut network, runtime) = self.connect_network()?; let file = self .preprocessed - .ok_or(MpcError("No proccesing file found"))?; + .ok_or(MpcError("No proccesing file found".to_string()))?; if self.use_32bit_field { - let mut context = preprocessing::load_context(file); - context.params.who_am_i = network.id(); + let context = + preprocessing::load_context(file).map_err(|e| MpcError(e.to_string()))?; + network.set_id(context.params.who_am_i); let engine = SpdzEngine32::new(network, runtime, context); Ok(AdderEngine::Spdz32(engine)) } else { - let mut context = preprocessing::load_context(file); - context.params.who_am_i = network.id(); + let context = + preprocessing::load_context(file).map_err(|e| MpcError(e.to_string()))?; + network.set_id(context.params.who_am_i); let engine = SpdzEngine::new(network, runtime, context); Ok(AdderEngine::Spdz(engine)) } } pub fn build_shamir(self) -> Result { - let threshold = self.threshold.ok_or(MpcError("No threshold found"))?; + let threshold = self + .threshold + .ok_or_else(|| MpcError("No threshold found".to_owned()))?; let (network, runtime) = self.connect_network()?; if self.use_32bit_field { let ids = network @@ -214,7 +220,9 @@ mod generic { } pub fn build_feldman(self) -> Result { - let threshold = self.threshold.ok_or(MpcError("No threshold found"))?; + let threshold = self + .threshold + .ok_or_else(|| MpcError("No threshold found".to_string()))?; let (network, runtime) = self.connect_network()?; let ids = network .participants() @@ -237,7 +245,7 @@ mod generic { let network = TcpNetwork::connect(my_addr, &others); let network = runtime .block_on(network) - .map_err(|_| MpcError("Failed to setup network"))?; + .map_err(|e| MpcError(format!("Failed to setup network: {e}")))?; Ok((network, runtime)) } @@ -362,35 +370,38 @@ mod test { let ctx1 = tempfile::tempfile().unwrap(); let ctx2 = tempfile::tempfile().unwrap(); let mut files = [ctx1, ctx2]; - do_preproc(&mut files, &[1, 1], false); + do_preproc(&mut files, &[1, 1], 0, false).unwrap(); let [mut ctx1, mut ctx2] = files; ctx1.rewind().unwrap(); ctx2.rewind().unwrap(); let t1 = thread::spawn(move || { - println!("[1] Setting up..."); - + let span = tracing::info_span!("Player-0"); + let _enter = span.enter(); + tracing::info!("Setting up..."); let mut engine = Engine::setup("127.0.0.1:1234") .add_participant("127.0.0.1:1235") .file_to_preprocessed(&mut ctx1) .build_spdz() .unwrap(); - println!("[1] Ready"); + tracing::info!("Ready"); let res = engine.mpc_sum(&[32.0]).unwrap(); - println!("[1] Done"); + tracing::info!("Done"); drop(engine); res }); std::thread::sleep(Duration::from_millis(50)); let t2 = thread::spawn(move || { - println!("[2] Setting up..."); + let span = tracing::info_span!("Player-1"); + let _enter = span.enter(); + tracing::info!("Setting up..."); let mut engine = Engine::setup("127.0.0.1:1235") .add_participant("127.0.0.1:1234") .file_to_preprocessed(&mut ctx2) .build_spdz() .unwrap(); - println!("[2] Ready"); + tracing::info!("Ready"); let res = engine.mpc_sum(&[32.0]).unwrap(); - println!("[2] Done"); + tracing::info!("Done"); drop(engine); res }); @@ -407,34 +418,38 @@ mod test { let ctx1 = tempfile::tempfile().unwrap(); let ctx2 = tempfile::tempfile().unwrap(); let mut files = [ctx1, ctx2]; - do_preproc(&mut files, &[2, 2], false); + do_preproc(&mut files, &[2, 2], 0, false).unwrap(); let [mut ctx1, mut ctx2] = files; ctx1.rewind().unwrap(); ctx2.rewind().unwrap(); let t1 = thread::spawn(move || { - println!("[1] Setting up..."); + let span = tracing::info_span!("Player-0"); + let _enter = span.enter(); + tracing::info!("Setting up..."); let mut engine = Engine::setup("127.0.0.1:2234") .add_participant("127.0.0.1:2235") .file_to_preprocessed(&mut ctx1) .build_spdz() .unwrap(); - println!("[1] Ready"); + tracing::info!("Ready"); let res = engine.mpc_sum(&[32.0, 11.9]).unwrap(); - println!("[1] Done"); + tracing::info!("Done"); drop(engine); res }); std::thread::sleep(Duration::from_millis(200)); let t2 = thread::spawn(move || { - println!("[2] Setting up..."); + let span = tracing::info_span!("Player-1"); + let _enter = span.enter(); + tracing::info!("Setting up..."); let mut engine = Engine::setup("127.0.0.1:2235") .add_participant("127.0.0.1:2234") .file_to_preprocessed(&mut ctx2) .build_spdz() .unwrap(); - println!("[2] Ready"); + tracing::info!("Ready"); let res = engine.mpc_sum(&[32.0, 24.1]).unwrap(); - println!("[2] Done"); + tracing::info!("Done"); drop(engine); res }); diff --git a/wecare/src/vm.rs b/wecare/src/vm.rs index f1154ce..1dde2cc 100644 --- a/wecare/src/vm.rs +++ b/wecare/src/vm.rs @@ -1,4 +1,5 @@ use std::{ + error::Error, fs::File, net::{SocketAddr, ToSocketAddrs}, }; @@ -11,7 +12,7 @@ use caring::{ algebra::{element::Element32, math::Vector}, net::{agency::Broadcast, connection::TcpConnection, network::TcpNetwork}, schemes::{feldman, shamir, spdz}, - vm::{self, parsing::Exp}, + vm::{self, parsing::Exp, ExecutionError}, }; pub use caring::net::Id; @@ -194,30 +195,30 @@ impl Engine { EngineBuilder::default() } - pub async fn execute(&mut self, expr: Opened) -> Value { + pub async fn execute(&mut self, expr: Opened) -> Result, ExecutionError> { let res: Value = match self { Engine::Spdz25519(engine) => { - let res = engine.execute(&expr.try_finalize().unwrap()).await; + let res = engine.execute(&expr.try_finalize().unwrap()).await?; res.map(|x| x.into()) } Engine::Shamir32(engine) => engine .execute(&expr.try_finalize().unwrap()) - .await + .await? .map(|x| x.into()), Engine::Spdz32(engine) => { - let res = engine.execute(&expr.try_finalize().unwrap()).await; + let res = engine.execute(&expr.try_finalize().unwrap()).await?; res.map(|x| x.into()) } Engine::Shamir25519(engine) => { - let res = engine.execute(&expr.try_finalize().unwrap()).await; + let res = engine.execute(&expr.try_finalize().unwrap()).await?; res.map(|x| x.into()) } Engine::Feldman25519(engine) => { - let res = engine.execute(&expr.try_finalize().unwrap()).await; + let res = engine.execute(&expr.try_finalize().unwrap()).await?; res.map(|x| x.into()) } }; - res + Ok(res) } pub fn id(&self) -> Id { @@ -236,6 +237,7 @@ impl Engine { }; self.execute(program) .await + .unwrap() .unwrap_vector() .into_iter() .map(|x| x.to_f64()) @@ -330,15 +332,15 @@ impl EngineBuilder { Ok(self) } - pub fn build(self) -> Engine { - let network = self.network.expect("No network installed!"); + pub fn build(self) -> Result> { + let mut network = self.network.expect("No network installed!"); let party_count = network.size(); let scheme = self.scheme.unwrap_or(SchemeKind::Shamir); let threshold = self.threshold.unwrap_or(party_count as u64); let field = self.field.unwrap_or(FieldKind::Curve25519); let rng = rand::rngs::StdRng::from_entropy(); - match (scheme, field) { + let engine = match (scheme, field) { (SchemeKind::Shamir, FieldKind::Curve25519) => { let ids = network .participants() @@ -357,13 +359,19 @@ impl EngineBuilder { } (SchemeKind::Spdz, FieldKind::Curve25519) => { let mut file = self.preprocesing.expect("Missing preproc!"); - let context = spdz::preprocessing::load_context(&mut file); - Engine::Spdz25519(vm::Engine::new(context, network, rng)) + let ctx = spdz::preprocessing::load_context(&mut file)?; + network.set_id(ctx.params.who_am_i); + let mut engine = vm::Engine::new(ctx, network, rng); + engine.load_context(); + Engine::Spdz25519(engine) } (SchemeKind::Spdz, FieldKind::Element32) => { let mut file = self.preprocesing.expect("Missing preproc!"); - let context = spdz::preprocessing::load_context(&mut file); - Engine::Spdz32(vm::Engine::new(context, network, rng)) + let context = spdz::preprocessing::load_context(&mut file)?; + network.set_id(context.params.who_am_i); + let mut engine = vm::Engine::new(context, network, rng); + engine.load_context(); + Engine::Spdz32(engine) } (SchemeKind::Feldman, FieldKind::Curve25519) => { let ids = network @@ -376,12 +384,18 @@ impl EngineBuilder { (SchemeKind::Feldman, FieldKind::Element32) => { panic!("Can't construct feldman from this field element. Missing group!") } - } + }; + Ok(engine) } } pub mod blocking { - use caring::{net::Id, vm::Value}; + use std::error::Error; + + use caring::{ + net::Id, + vm::{ExecutionError, Value}, + }; use crate::vm::UnknownNumber; @@ -427,17 +441,20 @@ pub mod blocking { Ok(self) } - pub fn build(self) -> Engine { - let parent = self.parent.build(); - Engine { + pub fn build(self) -> Result> { + let parent = self.parent.build()?; + Ok(Engine { runtime: self.runtime, parent, - } + }) } } impl Engine { - pub fn execute(&mut self, expr: super::Opened) -> Value { + pub fn execute( + &mut self, + expr: super::Opened, + ) -> Result, ExecutionError> { self.runtime.block_on(self.parent.execute(expr)) } @@ -477,6 +494,7 @@ mod test { .connect_blocking() .unwrap() .build() + .unwrap() } let addrs = ["127.0.0.1:3235", "127.0.0.1:3236", "127.0.0.1:3237"]; let res = thread::scope(|scope| { @@ -493,7 +511,7 @@ mod test { let script = res; println!("Party 0: Executing"); - let res = engine.execute(script); + let res = engine.execute(script).unwrap(); res.unwrap_single().to_f64() }), scope.spawn(|| { @@ -509,7 +527,7 @@ mod test { let script = res; println!("Party 1: Executing"); - let res = engine.execute(script); + let res = engine.execute(script).unwrap(); res.unwrap_single().to_f64() }), scope.spawn(|| { @@ -525,7 +543,7 @@ mod test { let script = res; println!("Party 2: Executing"); - let res = engine.execute(script); + let res = engine.execute(script).unwrap(); res.unwrap_single().to_f64() }), ]