From 5d4f19b0edcab69adf2a1733fa87b68203e8eeb1 Mon Sep 17 00:00:00 2001 From: natalie Date: Wed, 22 Mar 2023 23:41:26 +0000 Subject: [PATCH 01/12] Validate inputs for number of signers (#283) Prompt for input and handle errors --- Cargo.lock | 1207 +++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 + README.md | 2 + src/inputs.rs | 42 ++ src/main.rs | 18 +- src/tests.rs | 50 +- 6 files changed, 1316 insertions(+), 5 deletions(-) create mode 100644 src/inputs.rs diff --git a/Cargo.lock b/Cargo.lock index 2ab5e414..bbdbb6ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,1213 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "anes" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" + +[[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.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bit-set" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[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 = "bumpalo" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "cast" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" + +[[package]] +name = "cc" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "ciborium" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c137568cc60b904a7724001b35ce2630fd00d5d84805fbb608ab89509d788f" +dependencies = [ + "ciborium-io", + "ciborium-ll", + "serde", +] + +[[package]] +name = "ciborium-io" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "346de753af073cc87b52b2083a506b38ac176a44cfb05497b622e27be899b369" + +[[package]] +name = "ciborium-ll" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213030a2b5a4e0c0892b6652260cf6ccac84827b83a85a534e178e3906c4cf1b" +dependencies = [ + "ciborium-io", + "half", +] + +[[package]] +name = "clap" +version = "3.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" +dependencies = [ + "bitflags", + "clap_lex", + "indexmap", + "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 = "cpufeatures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" +dependencies = [ + "libc", +] + +[[package]] +name = "criterion" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7c76e09c1aae2bc52b3d2f29e13c6572553b30c4aa1b8a49fd70de6412654cb" +dependencies = [ + "anes", + "atty", + "cast", + "ciborium", + "clap", + "criterion-plot", + "itertools", + "lazy_static", + "num-traits", + "oorandom", + "plotters", + "rayon", + "regex", + "serde", + "serde_derive", + "serde_json", + "tinytemplate", + "walkdir", +] + +[[package]] +name = "criterion-plot" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" +dependencies = [ + "cast", + "itertools", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf2b3e8478797446514c91ef04bafcb59faba183e621ad488df88983cc14128c" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46bd5f3f85273295a9d14aedfb86f6aadbff6d8f5295c4a9edb08e819dcf5695" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "memoffset", + "scopeguard", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b" +dependencies = [ + "cfg-if", +] + +[[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.0.0-rc.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d4ba9852b42210c7538b75484f9daa0655e9a3ac04f693747bb0f02cf3cfe16" +dependencies = [ + "cfg-if", + "fiat-crypto", + "packed_simd_2", + "platforms", + "rand_core", + "serde", + "subtle", + "zeroize", +] + +[[package]] +name = "debugless-unwrap" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f400d0750c0c069e8493f2256cb4da6f604b6d2eeb69a0ca8863acde352f8400" + +[[package]] +name = "digest" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "either" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" + +[[package]] +name = "errno" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "fastrand" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" +dependencies = [ + "instant", +] + +[[package]] +name = "fiat-crypto" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93ace6ec7cc19c8ed33a32eaa9ea692d7faea05006b5356b9e2b668ec4bc3955" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "frost-core" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91fb3d5c476315934c0c097bb59f1f97ec735c25e54efec6417aec1805d6411" +dependencies = [ + "byteorder", + "criterion", + "debugless-unwrap", + "digest", + "hex", + "proptest", + "proptest-derive", + "rand_core", + "serde_json", + "thiserror", + "visibility", + "zeroize", +] + +[[package]] +name = "frost-ed25519" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "100cbe9e495922d9c381c4a9baf7341c6666f413227ec27cff3557f07dafe5ca" +dependencies = [ + "curve25519-dalek", + "frost-core", + "rand_core", + "sha2", +] + [[package]] name = "frost-trusted-dealer-demo" version = "0.1.0" +dependencies = [ + "frost-ed25519", + "thiserror", +] + +[[package]] +name = "generic-array" +version = "0.14.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "half" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[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.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +dependencies = [ + "libc", +] + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +dependencies = [ + "serde", +] + +[[package]] +name = "indexmap" +version = "1.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "io-lifetimes" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfa919a82ea574332e2de6e74b4c36e74d41982b335080fa59d4ef31be20fdf3" +dependencies = [ + "libc", + "windows-sys 0.45.0", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" + +[[package]] +name = "js-sys" +version = "0.3.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" +dependencies = [ + "wasm-bindgen", +] + +[[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.140" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" + +[[package]] +name = "libm" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fc7aa29613bd6a620df431842069224d8bc9011086b1db4c0e0cd47fa03ec9a" + +[[package]] +name = "libm" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb" + +[[package]] +name = "linux-raw-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "memoffset" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", + "libm 0.2.6", +] + +[[package]] +name = "num_cpus" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +dependencies = [ + "hermit-abi 0.2.6", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" + +[[package]] +name = "oorandom" +version = "11.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" + +[[package]] +name = "os_str_bytes" +version = "6.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" + +[[package]] +name = "packed_simd_2" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1914cd452d8fccd6f9db48147b29fd4ae05bea9dc5d9ad578509f72415de282" +dependencies = [ + "cfg-if", + "libm 0.1.4", +] + +[[package]] +name = "platforms" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d7ddaed09e0eb771a79ab0fd64609ba0afb0a8366421957936ad14cbd13630" + +[[package]] +name = "plotters" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2538b639e642295546c50fcd545198c9d64ee2a38620a628724a3b266d5fbf97" +dependencies = [ + "num-traits", + "plotters-backend", + "plotters-svg", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "plotters-backend" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "193228616381fecdc1224c62e96946dfbc73ff4384fba576e052ff8c1bea8142" + +[[package]] +name = "plotters-svg" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9a81d2759aae1dae668f783c308bc5c8ebd191ff4184aaa1b37f65a6ae5a56f" +dependencies = [ + "plotters-backend", +] + +[[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 = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +dependencies = [ + "unicode-xid 0.1.0", +] + +[[package]] +name = "proc-macro2" +version = "1.0.52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "proptest" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29f1b898011ce9595050a68e60f90bad083ff2987a695a42357134c8381fba70" +dependencies = [ + "bit-set", + "bitflags", + "byteorder", + "lazy_static", + "num-traits", + "quick-error 2.0.1", + "rand", + "rand_chacha", + "rand_xorshift", + "regex-syntax", + "rusty-fork", + "tempfile", + "unarray", +] + +[[package]] +name = "proptest-derive" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90b46295382dc76166cb7cf2bb4a97952464e4b7ed5a43e6cd34e1fec3349ddc" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "syn 0.15.44", +] + +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + +[[package]] +name = "quick-error" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" + +[[package]] +name = "quote" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" +dependencies = [ + "proc-macro2 0.4.30", +] + +[[package]] +name = "quote" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" +dependencies = [ + "proc-macro2 1.0.52", +] + +[[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 = "rand_xorshift" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" +dependencies = [ + "rand_core", +] + +[[package]] +name = "rayon" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "num_cpus", +] + +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags", +] + +[[package]] +name = "regex" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" +dependencies = [ + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" + +[[package]] +name = "rustix" +version = "0.36.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd5c6ff11fecd55b40746d1995a02f2eb375bf8c00d192d521ee09f42bef37bc" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys 0.45.0", +] + +[[package]] +name = "rusty-fork" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" +dependencies = [ + "fnv", + "quick-error 1.2.3", + "tempfile", + "wait-timeout", +] + +[[package]] +name = "ryu" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "serde" +version = "1.0.156" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "314b5b092c0ade17c00142951e50ced110ec27cea304b1037c6969246c2469a4" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.156" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7e29c4601e36bcec74a223228dce795f4cd3616341a4af93520ca1a837c087d" +dependencies = [ + "proc-macro2 1.0.52", + "quote 1.0.26", + "syn 1.0.109", +] + +[[package]] +name = "serde_json" +version = "1.0.94" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c533a59c9d8a93a09c6ab31f0fd5e5f4dd1b8fc9434804029839884765d04ea" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "subtle" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" + +[[package]] +name = "syn" +version = "0.15.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "unicode-xid 0.1.0", +] + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2 1.0.52", + "quote 1.0.26", + "unicode-ident", +] + +[[package]] +name = "synstructure" +version = "0.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" +dependencies = [ + "proc-macro2 1.0.52", + "quote 1.0.26", + "syn 1.0.109", + "unicode-xid 0.2.4", +] + +[[package]] +name = "tempfile" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af18f7ae1acd354b992402e9ec5864359d693cd8a79dcbef59f76891701c1e95" +dependencies = [ + "cfg-if", + "fastrand", + "redox_syscall", + "rustix", + "windows-sys 0.42.0", +] + +[[package]] +name = "textwrap" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" + +[[package]] +name = "thiserror" +version = "1.0.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5ab016db510546d856297882807df8da66a16fb8c4101cb8b30054b0d5b2d9c" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5420d42e90af0c38c3290abcca25b9b3bdf379fc9f55c528f53a269d9c9a267e" +dependencies = [ + "proc-macro2 1.0.52", + "quote 1.0.26", + "syn 1.0.109", +] + +[[package]] +name = "tinytemplate" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" +dependencies = [ + "serde", + "serde_json", +] + +[[package]] +name = "typenum" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" + +[[package]] +name = "unarray" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" + +[[package]] +name = "unicode-ident" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" + +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" + +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "visibility" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8881d5cc0ae34e3db2f1de5af81e5117a420d2f937506c2dc20d6f4cfb069051" +dependencies = [ + "proc-macro2 1.0.52", + "quote 1.0.26", + "syn 1.0.109", +] + +[[package]] +name = "wait-timeout" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +dependencies = [ + "libc", +] + +[[package]] +name = "walkdir" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" +dependencies = [ + "same-file", + "winapi", + "winapi-util", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2 1.0.52", + "quote 1.0.26", + "syn 1.0.109", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" +dependencies = [ + "quote 1.0.26", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" +dependencies = [ + "proc-macro2 1.0.52", + "quote 1.0.26", + "syn 1.0.109", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" + +[[package]] +name = "web-sys" +version = "0.3.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[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.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +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-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + +[[package]] +name = "zeroize" +version = "1.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c394b5bd0c6f669e7275d9c20aa90ae064cb22e75a1cad54e1b34088034b149f" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44bf07cb3e50ea2003396695d58bf46bc9887a1f362260446fad6bc4e79bd36c" +dependencies = [ + "proc-macro2 1.0.52", + "quote 1.0.26", + "syn 1.0.109", + "synstructure", +] diff --git a/Cargo.toml b/Cargo.toml index 16889918..e5cadcbe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,5 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +frost-ed25519 = "0.1.0" +thiserror = "1.0" diff --git a/README.md b/README.md index f88e7b17..4333e149 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ # Frost Trusted Dealer Demo A CLI demo for running trusted dealer key generation with FROST + +This demo uses ed25519 diff --git a/src/inputs.rs b/src/inputs.rs new file mode 100644 index 00000000..8f9b8d15 --- /dev/null +++ b/src/inputs.rs @@ -0,0 +1,42 @@ +use std::io; + +#[derive(Debug, PartialEq, Copy, Clone)] +pub struct Config { + pub min_signers: u16, + pub max_signers: u16, +} + +pub fn validate_inputs(config: &Config) -> Result { + if config.min_signers < 2 { + return Err(frost_ed25519::Error::InvalidMinSigners); + } + + if config.max_signers < 2 { + return Err(frost_ed25519::Error::InvalidMaxSigners); + } + + if config.min_signers > config.max_signers { + return Err(frost_ed25519::Error::InvalidMinSigners); + } + + Ok(*config) +} + +pub fn request_inputs() -> Config { + let mut min = "".to_string(); + + println!("The minimum number of signers:"); + io::stdin().read_line(&mut min); + let min_signers = min.trim().parse::().unwrap(); + + let mut max = "".to_string(); + + println!("The maximum number of signers:"); + io::stdin().read_line(&mut max); + let max_signers = max.trim().parse::().unwrap(); + + Config { + min_signers, + max_signers, + } +} diff --git a/src/main.rs b/src/main.rs index f3b78733..0c54c6be 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,20 @@ +mod inputs; #[cfg(test)] mod tests; -fn main() { - println!("Hello, world!"); +use std::io; + +use crate::inputs::{request_inputs, validate_inputs}; + +fn main() -> io::Result<()> { + let config = request_inputs(); + + let out = validate_inputs(&config); + + match out { + Ok(_) => (), + Err(e) => println!("An error occurred: {e}"), + } + + Ok(()) } diff --git a/src/tests.rs b/src/tests.rs index d20eaf75..f1a5fa8a 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,4 +1,48 @@ +use crate::inputs::{validate_inputs, Config}; + #[test] -fn check_test() { - assert!(1 == 1); -} \ No newline at end of file +fn check_valid_input_for_signers() { + let config = Config { + min_signers: 2, + max_signers: 3, + }; + + let expected = validate_inputs(&config); + + assert_eq!(expected, Ok(config)); +} + +#[test] +fn return_error_if_min_participant_greater_than_max_participant() { + let config = Config { + min_signers: 4, + max_signers: 3, + }; + + let expected = validate_inputs(&config); + + assert_eq!(expected, Err(frost_ed25519::Error::InvalidMinSigners)); +} +#[test] +fn return_error_if_min_participant_is_less_than_2() { + let config = Config { + min_signers: 1, + max_signers: 3, + }; + + let expected = validate_inputs(&config); + + assert_eq!(expected, Err(frost_ed25519::Error::InvalidMinSigners)); +} + +#[test] +fn return_error_if_max_participant_is_less_than_2() { + let config = Config { + min_signers: 2, + max_signers: 1, + }; + + let expected = validate_inputs(&config); + + assert_eq!(expected, Err(frost_ed25519::Error::InvalidMaxSigners)); +} From f179ff842100a56fc6b1f32ffc1fc98780b27d43 Mon Sep 17 00:00:00 2001 From: Natalie Eskinazi Date: Tue, 11 Apr 2023 13:56:23 +0100 Subject: [PATCH 02/12] Validate inputs (#283) --- LICENSE-APACHE | 0 LICENSE-MIT | 0 README.md | 2 ++ src/inputs.rs | 0 src/tests/inputs_tests.rs | 49 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 51 insertions(+) mode change 100644 => 100755 LICENSE-APACHE mode change 100644 => 100755 LICENSE-MIT mode change 100644 => 100755 README.md mode change 100644 => 100755 src/inputs.rs create mode 100755 src/tests/inputs_tests.rs diff --git a/LICENSE-APACHE b/LICENSE-APACHE old mode 100644 new mode 100755 diff --git a/LICENSE-MIT b/LICENSE-MIT old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 4333e149..1f27d62a --- a/README.md +++ b/README.md @@ -3,3 +3,5 @@ A CLI demo for running trusted dealer key generation with FROST This demo uses ed25519 + +https://crates.io/crates/frost-ed25519 diff --git a/src/inputs.rs b/src/inputs.rs old mode 100644 new mode 100755 diff --git a/src/tests/inputs_tests.rs b/src/tests/inputs_tests.rs new file mode 100755 index 00000000..553d3bd4 --- /dev/null +++ b/src/tests/inputs_tests.rs @@ -0,0 +1,49 @@ +use crate::inputs::{validate_inputs, Config}; + +#[test] +fn check_valid_input_for_signers() { + let config = Config { + min_signers: 2, + max_signers: 3, + }; + + let expected = validate_inputs(&config); + + assert_eq!(expected, Ok(config)); +} + +#[test] +fn return_error_if_min_participant_greater_than_max_participant() { + let config = Config { + min_signers: 4, + max_signers: 3, + }; + + let expected = validate_inputs(&config); + + assert_eq!(expected, Err(frost_ed25519::Error::InvalidMinSigners)); +} + +#[test] +fn return_error_if_min_participant_is_less_than_2() { + let config = Config { + min_signers: 1, + max_signers: 3, + }; + + let expected = validate_inputs(&config); + + assert_eq!(expected, Err(frost_ed25519::Error::InvalidMinSigners)); +} + +#[test] +fn return_error_if_max_participant_is_less_than_2() { + let config = Config { + min_signers: 2, + max_signers: 1, + }; + + let expected = validate_inputs(&config); + + assert_eq!(expected, Err(frost_ed25519::Error::InvalidMaxSigners)); +} From 4b25c4b7a4150c3614443947e711de7fe9fac0c2 Mon Sep 17 00:00:00 2001 From: natalie Date: Tue, 11 Apr 2023 16:05:05 +0100 Subject: [PATCH 03/12] Print group public key (#283) Keygen implementation Fix APACHE License --- .gitignore | 1 + Cargo.lock | 232 +++++++++++++++++++++------------ Cargo.toml | 2 + LICENSE-APACHE | 2 +- src/keygen.rs | 79 +++++++++++ src/main.rs | 15 +++ src/tests.rs | 50 +------ src/tests/integration_tests.rs | 13 ++ 8 files changed, 264 insertions(+), 130 deletions(-) mode change 100644 => 100755 .gitignore create mode 100755 src/keygen.rs mode change 100644 => 100755 src/main.rs mode change 100644 => 100755 src/tests.rs create mode 100644 src/tests/integration_tests.rs diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 index ea8c4bf7..87fe809d --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +.vscode/* \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index bbdbb6ee..c20b3bcc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -135,9 +135,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" +checksum = "280a9f2d8b3a38871a3c8a46fb80db65e5e5ed97da80c4d08bf27fb63e35e181" dependencies = [ "libc", ] @@ -180,9 +180,9 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.7" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf2b3e8478797446514c91ef04bafcb59faba183e621ad488df88983cc14128c" +checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" dependencies = [ "cfg-if", "crossbeam-utils", @@ -271,13 +271,13 @@ checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" [[package]] name = "errno" -version = "0.2.8" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" dependencies = [ "errno-dragonfly", "libc", - "winapi", + "windows-sys 0.48.0", ] [[package]] @@ -301,9 +301,9 @@ dependencies = [ [[package]] name = "fiat-crypto" -version = "0.1.19" +version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93ace6ec7cc19c8ed33a32eaa9ea692d7faea05006b5356b9e2b668ec4bc3955" +checksum = "e825f6987101665dea6ec934c09ec6d721de7bc1bf92248e1d5810c8cd636b77" [[package]] name = "fnv" @@ -348,14 +348,16 @@ name = "frost-trusted-dealer-demo" version = "0.1.0" dependencies = [ "frost-ed25519", + "hex", + "rand", "thiserror", ] [[package]] name = "generic-array" -version = "0.14.6" +version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", @@ -363,9 +365,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4" dependencies = [ "cfg-if", "libc", @@ -402,6 +404,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" + [[package]] name = "hex" version = "0.4.3" @@ -413,9 +421,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.9.2" +version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", "hashbrown", @@ -432,12 +440,13 @@ dependencies = [ [[package]] name = "io-lifetimes" -version = "1.0.6" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfa919a82ea574332e2de6e74b4c36e74d41982b335080fa59d4ef31be20fdf3" +checksum = "9c66c74d2ae7e79a5a8f7ac924adbe38ee42a859c6539ad869eb51f0b52dc220" dependencies = [ + "hermit-abi 0.3.1", "libc", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -472,9 +481,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.140" +version = "0.2.141" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" +checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" [[package]] name = "libm" @@ -490,9 +499,9 @@ checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb" [[package]] name = "linux-raw-sys" -version = "0.1.4" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" +checksum = "d59d8c75012853d2e872fb56bc8a2e53718e2cafe1a4c823143141c6d90c322f" [[package]] name = "log" @@ -546,9 +555,9 @@ checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" [[package]] name = "os_str_bytes" -version = "6.4.1" +version = "6.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" +checksum = "ceedf44fb00f2d1984b0bc98102627ce622e083e49a5bacdb3e514fa4238e267" [[package]] name = "packed_simd_2" @@ -611,9 +620,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.52" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224" +checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" dependencies = [ "unicode-ident", ] @@ -677,7 +686,7 @@ version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" dependencies = [ - "proc-macro2 1.0.52", + "proc-macro2 1.0.56", ] [[package]] @@ -743,40 +752,40 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.16" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" dependencies = [ "bitflags", ] [[package]] name = "regex" -version = "1.7.1" +version = "1.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" +checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d" dependencies = [ "regex-syntax", ] [[package]] name = "regex-syntax" -version = "0.6.28" +version = "0.6.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "rustix" -version = "0.36.9" +version = "0.37.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd5c6ff11fecd55b40746d1995a02f2eb375bf8c00d192d521ee09f42bef37bc" +checksum = "85597d61f83914ddeba6a47b3b8ffe7365107221c2e557ed94426489fefb5f77" dependencies = [ "bitflags", "errno", "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -814,29 +823,29 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.156" +version = "1.0.160" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "314b5b092c0ade17c00142951e50ced110ec27cea304b1037c6969246c2469a4" +checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.156" +version = "1.0.160" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7e29c4601e36bcec74a223228dce795f4cd3616341a4af93520ca1a837c087d" +checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df" dependencies = [ - "proc-macro2 1.0.52", + "proc-macro2 1.0.56", "quote 1.0.26", - "syn 1.0.109", + "syn 2.0.14", ] [[package]] name = "serde_json" -version = "1.0.94" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c533a59c9d8a93a09c6ab31f0fd5e5f4dd1b8fc9434804029839884765d04ea" +checksum = "d721eca97ac802aa7777b701877c8004d950fc142651367300d21c1cc0194744" dependencies = [ "itoa", "ryu", @@ -877,7 +886,18 @@ version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ - "proc-macro2 1.0.52", + "proc-macro2 1.0.56", + "quote 1.0.26", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcf316d5356ed6847742d036f8a39c3b8435cac10bd528a4bd461928a6ab34d5" +dependencies = [ + "proc-macro2 1.0.56", "quote 1.0.26", "unicode-ident", ] @@ -888,7 +908,7 @@ version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" dependencies = [ - "proc-macro2 1.0.52", + "proc-macro2 1.0.56", "quote 1.0.26", "syn 1.0.109", "unicode-xid 0.2.4", @@ -896,15 +916,15 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.4.0" +version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af18f7ae1acd354b992402e9ec5864359d693cd8a79dcbef59f76891701c1e95" +checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998" dependencies = [ "cfg-if", "fastrand", "redox_syscall", "rustix", - "windows-sys 0.42.0", + "windows-sys 0.45.0", ] [[package]] @@ -915,22 +935,22 @@ checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" [[package]] name = "thiserror" -version = "1.0.39" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5ab016db510546d856297882807df8da66a16fb8c4101cb8b30054b0d5b2d9c" +checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.39" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5420d42e90af0c38c3290abcca25b9b3bdf379fc9f55c528f53a269d9c9a267e" +checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ - "proc-macro2 1.0.52", + "proc-macro2 1.0.56", "quote 1.0.26", - "syn 1.0.109", + "syn 2.0.14", ] [[package]] @@ -985,7 +1005,7 @@ version = "0.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8881d5cc0ae34e3db2f1de5af81e5117a420d2f937506c2dc20d6f4cfb069051" dependencies = [ - "proc-macro2 1.0.52", + "proc-macro2 1.0.56", "quote 1.0.26", "syn 1.0.109", ] @@ -1001,12 +1021,11 @@ dependencies = [ [[package]] name = "walkdir" -version = "2.3.2" +version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" +checksum = "36df944cda56c7d8d8b7496af378e6b16de9284591917d307c9b4d313c44e698" dependencies = [ "same-file", - "winapi", "winapi-util", ] @@ -1035,7 +1054,7 @@ dependencies = [ "bumpalo", "log", "once_cell", - "proc-macro2 1.0.52", + "proc-macro2 1.0.56", "quote 1.0.26", "syn 1.0.109", "wasm-bindgen-shared", @@ -1057,7 +1076,7 @@ version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ - "proc-macro2 1.0.52", + "proc-macro2 1.0.56", "quote 1.0.26", "syn 1.0.109", "wasm-bindgen-backend", @@ -1113,26 +1132,20 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-sys" -version = "0.42.0" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows-targets 0.42.2", ] [[package]] name = "windows-sys" -version = "0.45.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets", + "windows-targets 0.48.0", ] [[package]] @@ -1141,13 +1154,28 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-targets" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +dependencies = [ + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", ] [[package]] @@ -1156,42 +1184,84 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + [[package]] name = "windows_aarch64_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + [[package]] name = "windows_i686_gnu" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + [[package]] name = "windows_i686_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + [[package]] name = "windows_x86_64_gnu" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + [[package]] name = "windows_x86_64_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + [[package]] name = "zeroize" version = "1.5.7" @@ -1207,7 +1277,7 @@ version = "1.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44bf07cb3e50ea2003396695d58bf46bc9887a1f362260446fad6bc4e79bd36c" dependencies = [ - "proc-macro2 1.0.52", + "proc-macro2 1.0.56", "quote 1.0.26", "syn 1.0.109", "synstructure", diff --git a/Cargo.toml b/Cargo.toml index e5cadcbe..4ed6f18d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,5 @@ edition = "2021" [dependencies] frost-ed25519 = "0.1.0" thiserror = "1.0" +rand = "0.8" +hex = "0.4" diff --git a/LICENSE-APACHE b/LICENSE-APACHE index a7fccb54..9eec509d 100755 --- a/LICENSE-APACHE +++ b/LICENSE-APACHE @@ -188,7 +188,7 @@ APPENDIX: How to apply the Apache License to your work. same "printed page" as the copyright notice for easier identification within third-party archives. -Copyright 2023 Zcash Foundation +Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/keygen.rs b/src/keygen.rs new file mode 100755 index 00000000..a0016cd3 --- /dev/null +++ b/src/keygen.rs @@ -0,0 +1,79 @@ +use frost::keys::KeyPackage; +use frost::round1::{SigningCommitments, SigningNonces}; +use frost::round2::SignatureShare; +use frost::{Identifier, SigningPackage, VerifyingKey}; +use frost_ed25519 as frost; +use rand::rngs::ThreadRng; +use rand::thread_rng; +use std::collections::HashMap; + +use crate::inputs::Config; + +pub fn keygen(config: Config) -> Result { + let mut rng = thread_rng(); + let max_signers = config.max_signers; + let min_signers = config.min_signers; + let (shares, pubkeys) = frost::keys::keygen_with_dealer(max_signers, min_signers, &mut rng)?; + + let key_packages: HashMap<_, _> = shares + .into_iter() + .map(|share| Ok((share.identifier, frost::keys::KeyPackage::try_from(share)?))) + .collect::>()?; + + let (nonces, commitments) = generate_nonces_and_commitments(min_signers, &key_packages, rng); + let message = "message to sign".as_bytes(); // TODO: choose message + let comms = commitments.into_values().collect(); + let signing_package = frost::SigningPackage::new(comms, message.to_vec()); + let signature_shares = generate_signature_shares(nonces, &key_packages, &signing_package); + let group_signature = frost::aggregate(&signing_package, &signature_shares[..], &pubkeys)?; + let verify_signature = pubkeys.group_public.verify(message, &group_signature); + + match verify_signature { + Ok(_) => Ok(pubkeys.group_public), + Err(_) => Err(frost::Error::InvalidSignature), // TODO: Use correct error + } +} + +fn generate_nonces_and_commitments( + min_signers: u16, + key_packages: &HashMap, + mut rng: ThreadRng, +) -> ( + HashMap, + HashMap, +) { + let mut nonces = HashMap::new(); + let mut commitments = HashMap::new(); + + for participant_index in 1..(min_signers + 1) { + let participant_identifier = participant_index.try_into().expect("should be nonzero"); + let (nonce, commitment) = frost::round1::commit( + participant_identifier, + key_packages[&participant_identifier].secret_share(), + &mut rng, + ); + nonces.insert(participant_identifier, nonce); + commitments.insert(participant_identifier, commitment); + } + + (nonces, commitments) +} + +fn generate_signature_shares( + nonces: HashMap, + key_packages: &HashMap, + signing_package: &SigningPackage, +) -> Vec { + let mut signature_shares = Vec::new(); + + for participant_identifier in nonces.keys() { + let key_package = &key_packages[participant_identifier]; + let nonces_to_use = &nonces[participant_identifier]; + let signature_share = + frost::round2::sign(signing_package, nonces_to_use, key_package).unwrap(); //TODO: handle errors + + signature_shares.push(signature_share); + } + + signature_shares +} diff --git a/src/main.rs b/src/main.rs old mode 100644 new mode 100755 index 0c54c6be..ac26a74d --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,18 @@ mod inputs; +mod keygen; #[cfg(test)] mod tests; use std::io; +use frost::VerifyingKey; +use frost_ed25519 as frost; +use keygen::keygen; + use crate::inputs::{request_inputs, validate_inputs}; fn main() -> io::Result<()> { + // TODO: error handling let config = request_inputs(); let out = validate_inputs(&config); @@ -16,5 +22,14 @@ fn main() -> io::Result<()> { Err(e) => println!("An error occurred: {e}"), } + // Print outputs + let keygen = keygen(config).unwrap(); + + print_values(&keygen); + Ok(()) } + +fn print_values(group_public_key: &VerifyingKey) { + println!("Group public key: {:?}", &group_public_key.to_bytes()); +} diff --git a/src/tests.rs b/src/tests.rs old mode 100644 new mode 100755 index f1a5fa8a..53ba1abe --- a/src/tests.rs +++ b/src/tests.rs @@ -1,48 +1,2 @@ -use crate::inputs::{validate_inputs, Config}; - -#[test] -fn check_valid_input_for_signers() { - let config = Config { - min_signers: 2, - max_signers: 3, - }; - - let expected = validate_inputs(&config); - - assert_eq!(expected, Ok(config)); -} - -#[test] -fn return_error_if_min_participant_greater_than_max_participant() { - let config = Config { - min_signers: 4, - max_signers: 3, - }; - - let expected = validate_inputs(&config); - - assert_eq!(expected, Err(frost_ed25519::Error::InvalidMinSigners)); -} -#[test] -fn return_error_if_min_participant_is_less_than_2() { - let config = Config { - min_signers: 1, - max_signers: 3, - }; - - let expected = validate_inputs(&config); - - assert_eq!(expected, Err(frost_ed25519::Error::InvalidMinSigners)); -} - -#[test] -fn return_error_if_max_participant_is_less_than_2() { - let config = Config { - min_signers: 2, - max_signers: 1, - }; - - let expected = validate_inputs(&config); - - assert_eq!(expected, Err(frost_ed25519::Error::InvalidMaxSigners)); -} +mod inputs_tests; +mod integration_tests; diff --git a/src/tests/integration_tests.rs b/src/tests/integration_tests.rs new file mode 100644 index 00000000..2f97857d --- /dev/null +++ b/src/tests/integration_tests.rs @@ -0,0 +1,13 @@ +use crate::{inputs::Config, keygen}; + +#[test] +fn check_keygen() { + let config = Config { + min_signers: 2, + max_signers: 3, + }; + + let keygen = keygen(config); + + assert!(keygen.is_ok()); +} From 78f0952730e3f9fd44405c288c2f55b7f0e63186 Mon Sep 17 00:00:00 2001 From: natalie Date: Wed, 12 Apr 2023 11:09:28 +0100 Subject: [PATCH 04/12] Create Output struct (#283) --- src/keygen.rs | 12 ++++++++++-- src/main.rs | 10 ++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/keygen.rs b/src/keygen.rs index a0016cd3..a7a5e6dc 100755 --- a/src/keygen.rs +++ b/src/keygen.rs @@ -9,7 +9,7 @@ use std::collections::HashMap; use crate::inputs::Config; -pub fn keygen(config: Config) -> Result { +pub fn keygen(config: Config) -> Result { let mut rng = thread_rng(); let max_signers = config.max_signers; let min_signers = config.min_signers; @@ -28,12 +28,20 @@ pub fn keygen(config: Config) -> Result { let group_signature = frost::aggregate(&signing_package, &signature_shares[..], &pubkeys)?; let verify_signature = pubkeys.group_public.verify(message, &group_signature); + let output = Output { + group_public_key: pubkeys.group_public, + }; + match verify_signature { - Ok(_) => Ok(pubkeys.group_public), + Ok(_) => Ok(output), Err(_) => Err(frost::Error::InvalidSignature), // TODO: Use correct error } } +pub struct Output { + pub group_public_key: VerifyingKey, +} + fn generate_nonces_and_commitments( min_signers: u16, key_packages: &HashMap, diff --git a/src/main.rs b/src/main.rs index ac26a74d..914810e6 100755 --- a/src/main.rs +++ b/src/main.rs @@ -5,9 +5,7 @@ mod tests; use std::io; -use frost::VerifyingKey; -use frost_ed25519 as frost; -use keygen::keygen; +use keygen::{keygen, Output}; use crate::inputs::{request_inputs, validate_inputs}; @@ -25,11 +23,11 @@ fn main() -> io::Result<()> { // Print outputs let keygen = keygen(config).unwrap(); - print_values(&keygen); + print_values(keygen); Ok(()) } -fn print_values(group_public_key: &VerifyingKey) { - println!("Group public key: {:?}", &group_public_key.to_bytes()); +fn print_values(output: Output) { + println!("Group public key: {:?}", output.group_public_key.to_bytes()); } From fa62953fa00a672da6577f90a77138c117b7570b Mon Sep 17 00:00:00 2001 From: natalie Date: Mon, 17 Apr 2023 16:16:24 +0100 Subject: [PATCH 05/12] Return secret shares and public keys for all participants --- src/main.rs | 27 ++++++++--- src/tests.rs | 2 +- src/tests/integration_test.rs | 28 ++++++++++++ .../integration_test/signature_gen.rs} | 45 +++---------------- src/tests/integration_tests.rs | 13 ------ src/trusted_dealer_keygen.rs | 23 ++++++++++ 6 files changed, 78 insertions(+), 60 deletions(-) create mode 100644 src/tests/integration_test.rs rename src/{keygen.rs => tests/integration_test/signature_gen.rs} (50%) mode change 100755 => 100644 delete mode 100644 src/tests/integration_tests.rs create mode 100644 src/trusted_dealer_keygen.rs diff --git a/src/main.rs b/src/main.rs index 914810e6..441671d5 100755 --- a/src/main.rs +++ b/src/main.rs @@ -1,17 +1,24 @@ mod inputs; -mod keygen; #[cfg(test)] mod tests; +mod trusted_dealer_keygen; +use std::collections::HashMap; use std::io; -use keygen::{keygen, Output}; +use frost_ed25519 as frost; + +use frost::keys::KeyPackage; +use frost::{Identifier, VerifyingKey}; +use rand::thread_rng; use crate::inputs::{request_inputs, validate_inputs}; +use crate::trusted_dealer_keygen::trusted_dealer_keygen; fn main() -> io::Result<()> { // TODO: error handling let config = request_inputs(); + let mut rng = thread_rng(); let out = validate_inputs(&config); @@ -21,13 +28,21 @@ fn main() -> io::Result<()> { } // Print outputs - let keygen = keygen(config).unwrap(); + let (key_packages, pubkeys) = trusted_dealer_keygen(config, &mut rng); - print_values(keygen); + print_values(key_packages, pubkeys.group_public); Ok(()) } -fn print_values(output: Output) { - println!("Group public key: {:?}", output.group_public_key.to_bytes()); +fn print_values(keys: HashMap, group_public_key: VerifyingKey) { + println!("Group public key: {:x?}", group_public_key.to_bytes()); + println!("---"); + + for (k, v) in keys { + println!("Participant {:?}", k); + println!("Secret share: {:x?}", v.secret_share.to_bytes()); + println!("Public key: {:x?}", v.public.to_bytes()); + println!("---") + } } diff --git a/src/tests.rs b/src/tests.rs index 53ba1abe..0d3354ba 100755 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,2 +1,2 @@ mod inputs_tests; -mod integration_tests; +mod integration_test; diff --git a/src/tests/integration_test.rs b/src/tests/integration_test.rs new file mode 100644 index 00000000..a160c0a4 --- /dev/null +++ b/src/tests/integration_test.rs @@ -0,0 +1,28 @@ +use crate::inputs::Config; +use frost_ed25519 as frost; +use rand::thread_rng; + +use crate::trusted_dealer_keygen::trusted_dealer_keygen; +mod signature_gen; + +#[test] +fn check_keygen() { + let mut rng = thread_rng(); + let config = Config { + min_signers: 2, + max_signers: 3, + }; + let (key_packages, pubkeys) = trusted_dealer_keygen(config, &mut rng); + let (nonces, commitments) = + signature_gen::generate_nonces_and_commitments(config.min_signers, &key_packages, &mut rng); + let message = "message to sign".as_bytes(); + let comms = commitments.into_values().collect(); + let signing_package = frost::SigningPackage::new(comms, message.to_vec()); + let signature_shares = + signature_gen::generate_signature_shares(nonces, &key_packages, &signing_package); + let group_signature = + frost::aggregate(&signing_package, &signature_shares[..], &pubkeys).unwrap(); + let verify_signature = pubkeys.group_public.verify(message, &group_signature); + + assert!(verify_signature.is_ok()); +} diff --git a/src/keygen.rs b/src/tests/integration_test/signature_gen.rs old mode 100755 new mode 100644 similarity index 50% rename from src/keygen.rs rename to src/tests/integration_test/signature_gen.rs index a7a5e6dc..39e2a515 --- a/src/keygen.rs +++ b/src/tests/integration_test/signature_gen.rs @@ -1,4 +1,4 @@ -use frost::keys::KeyPackage; +use frost::keys::{KeyPackage, SecretShare}; use frost::round1::{SigningCommitments, SigningNonces}; use frost::round2::SignatureShare; use frost::{Identifier, SigningPackage, VerifyingKey}; @@ -7,45 +7,10 @@ use rand::rngs::ThreadRng; use rand::thread_rng; use std::collections::HashMap; -use crate::inputs::Config; - -pub fn keygen(config: Config) -> Result { - let mut rng = thread_rng(); - let max_signers = config.max_signers; - let min_signers = config.min_signers; - let (shares, pubkeys) = frost::keys::keygen_with_dealer(max_signers, min_signers, &mut rng)?; - - let key_packages: HashMap<_, _> = shares - .into_iter() - .map(|share| Ok((share.identifier, frost::keys::KeyPackage::try_from(share)?))) - .collect::>()?; - - let (nonces, commitments) = generate_nonces_and_commitments(min_signers, &key_packages, rng); - let message = "message to sign".as_bytes(); // TODO: choose message - let comms = commitments.into_values().collect(); - let signing_package = frost::SigningPackage::new(comms, message.to_vec()); - let signature_shares = generate_signature_shares(nonces, &key_packages, &signing_package); - let group_signature = frost::aggregate(&signing_package, &signature_shares[..], &pubkeys)?; - let verify_signature = pubkeys.group_public.verify(message, &group_signature); - - let output = Output { - group_public_key: pubkeys.group_public, - }; - - match verify_signature { - Ok(_) => Ok(output), - Err(_) => Err(frost::Error::InvalidSignature), // TODO: Use correct error - } -} - -pub struct Output { - pub group_public_key: VerifyingKey, -} - -fn generate_nonces_and_commitments( +pub fn generate_nonces_and_commitments( min_signers: u16, key_packages: &HashMap, - mut rng: ThreadRng, + rng: &mut ThreadRng, ) -> ( HashMap, HashMap, @@ -58,7 +23,7 @@ fn generate_nonces_and_commitments( let (nonce, commitment) = frost::round1::commit( participant_identifier, key_packages[&participant_identifier].secret_share(), - &mut rng, + rng, ); nonces.insert(participant_identifier, nonce); commitments.insert(participant_identifier, commitment); @@ -67,7 +32,7 @@ fn generate_nonces_and_commitments( (nonces, commitments) } -fn generate_signature_shares( +pub fn generate_signature_shares( nonces: HashMap, key_packages: &HashMap, signing_package: &SigningPackage, diff --git a/src/tests/integration_tests.rs b/src/tests/integration_tests.rs deleted file mode 100644 index 2f97857d..00000000 --- a/src/tests/integration_tests.rs +++ /dev/null @@ -1,13 +0,0 @@ -use crate::{inputs::Config, keygen}; - -#[test] -fn check_keygen() { - let config = Config { - min_signers: 2, - max_signers: 3, - }; - - let keygen = keygen(config); - - assert!(keygen.is_ok()); -} diff --git a/src/trusted_dealer_keygen.rs b/src/trusted_dealer_keygen.rs new file mode 100644 index 00000000..6ac71a5d --- /dev/null +++ b/src/trusted_dealer_keygen.rs @@ -0,0 +1,23 @@ +use frost::keys::{KeyPackage, PublicKeyPackage}; +use frost::Identifier; +use frost_ed25519 as frost; +use rand::rngs::ThreadRng; +use std::collections::HashMap; + +use crate::inputs::Config; + +pub fn trusted_dealer_keygen( + config: Config, + rng: &mut ThreadRng, +) -> (HashMap, PublicKeyPackage) { + let (shares, pubkeys) = + frost::keys::keygen_with_dealer(config.max_signers, config.min_signers, rng).unwrap(); // TODO: handle error + + let key_packages: HashMap<_, _> = shares + .into_iter() + .map(|share| Ok((share.identifier, frost::keys::KeyPackage::try_from(share)?))) + .collect::>() + .unwrap(); // TODO: handle error + + (key_packages, pubkeys) +} From ed59cfee31ab1da81aa125dce5eaeb1aba746135 Mon Sep 17 00:00:00 2001 From: natalie Date: Mon, 17 Apr 2023 16:20:17 +0100 Subject: [PATCH 06/12] Only generate keys if inputs are validated (#283) Remove unused imports --- src/main.rs | 8 +++++--- src/tests/integration_test/signature_gen.rs | 5 ++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 441671d5..d5eae20e 100755 --- a/src/main.rs +++ b/src/main.rs @@ -27,10 +27,12 @@ fn main() -> io::Result<()> { Err(e) => println!("An error occurred: {e}"), } - // Print outputs - let (key_packages, pubkeys) = trusted_dealer_keygen(config, &mut rng); + if out.is_ok() { + // Print outputs + let (key_packages, pubkeys) = trusted_dealer_keygen(config, &mut rng); - print_values(key_packages, pubkeys.group_public); + print_values(key_packages, pubkeys.group_public); + } Ok(()) } diff --git a/src/tests/integration_test/signature_gen.rs b/src/tests/integration_test/signature_gen.rs index 39e2a515..a48fa28a 100644 --- a/src/tests/integration_test/signature_gen.rs +++ b/src/tests/integration_test/signature_gen.rs @@ -1,10 +1,9 @@ -use frost::keys::{KeyPackage, SecretShare}; +use frost::keys::KeyPackage; use frost::round1::{SigningCommitments, SigningNonces}; use frost::round2::SignatureShare; -use frost::{Identifier, SigningPackage, VerifyingKey}; +use frost::{Identifier, SigningPackage}; use frost_ed25519 as frost; use rand::rngs::ThreadRng; -use rand::thread_rng; use std::collections::HashMap; pub fn generate_nonces_and_commitments( From beed96887f8e7d354cc1c5316e86637cfb9e9dc8 Mon Sep 17 00:00:00 2001 From: natalie Date: Mon, 24 Apr 2023 09:58:29 +0100 Subject: [PATCH 07/12] Add comment for getting value of commitment (#283) --- src/main.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index d5eae20e..0db6f95d 100755 --- a/src/main.rs +++ b/src/main.rs @@ -8,8 +8,8 @@ use std::io; use frost_ed25519 as frost; -use frost::keys::KeyPackage; -use frost::{Identifier, VerifyingKey}; +use frost::keys::{KeyPackage, PublicKeyPackage}; +use frost::Identifier; use rand::thread_rng; use crate::inputs::{request_inputs, validate_inputs}; @@ -31,14 +31,17 @@ fn main() -> io::Result<()> { // Print outputs let (key_packages, pubkeys) = trusted_dealer_keygen(config, &mut rng); - print_values(key_packages, pubkeys.group_public); + print_values(key_packages, pubkeys); } Ok(()) } -fn print_values(keys: HashMap, group_public_key: VerifyingKey) { - println!("Group public key: {:x?}", group_public_key.to_bytes()); +fn print_values(keys: HashMap, pubkeys: PublicKeyPackage) { + println!("Group public key: {:x?}", pubkeys.group_public.to_bytes()); + // Need to be able to extract value for VerifiableSecretSharingCommitment that isn't currently accessible + // println!("Commitment: {:x?}", shares[0].commitment[0]); + println!("---"); for (k, v) in keys { From 806d0e558b23cf523ad5d063844da8ce365d91ec Mon Sep 17 00:00:00 2001 From: natalie Date: Tue, 25 Apr 2023 14:40:55 +0100 Subject: [PATCH 08/12] Temporarily return ok value for inputs to resolve clippy issue (#283) --- src/inputs.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/inputs.rs b/src/inputs.rs index 8f9b8d15..43ce6d53 100755 --- a/src/inputs.rs +++ b/src/inputs.rs @@ -26,13 +26,13 @@ pub fn request_inputs() -> Config { let mut min = "".to_string(); println!("The minimum number of signers:"); - io::stdin().read_line(&mut min); + io::stdin().read_line(&mut min).unwrap(); // TODO: handle errors let min_signers = min.trim().parse::().unwrap(); let mut max = "".to_string(); println!("The maximum number of signers:"); - io::stdin().read_line(&mut max); + io::stdin().read_line(&mut max).unwrap(); // TODO: handle errors let max_signers = max.trim().parse::().unwrap(); Config { From a8710860d18afd09fb24fde210537236361accb8 Mon Sep 17 00:00:00 2001 From: natalie Date: Tue, 25 Apr 2023 14:54:17 +0100 Subject: [PATCH 09/12] Update frost-ed25519 to v0.2.0 (#325) --- Cargo.lock | 91 ++++++++++++++++-------------------- Cargo.toml | 2 +- src/trusted_dealer_keygen.rs | 11 +++-- 3 files changed, 46 insertions(+), 58 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c20b3bcc..b63b3420 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -57,9 +57,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.12.0" +version = "3.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" +checksum = "9b1ce199063694f33ffb7dd4e0ee620741495c32833cde5aa08f02a0bf96f0c8" [[package]] name = "byteorder" @@ -135,9 +135,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "280a9f2d8b3a38871a3c8a46fb80db65e5e5ed97da80c4d08bf27fb63e35e181" +checksum = "3e4c1eaa2012c47becbbad2ab175484c2a84d1185b566fb2cc5b8707343dfe58" dependencies = [ "libc", ] @@ -233,9 +233,9 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "4.0.0-rc.1" +version = "4.0.0-rc.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d4ba9852b42210c7538b75484f9daa0655e9a3ac04f693747bb0f02cf3cfe16" +checksum = "03d928d978dbec61a1167414f5ec534f24bea0d7a0d24dd9b6233d3d8223e585" dependencies = [ "cfg-if", "fiat-crypto", @@ -313,9 +313,9 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "frost-core" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f91fb3d5c476315934c0c097bb59f1f97ec735c25e54efec6417aec1805d6411" +checksum = "05b1dfe39cf39c73c9d2b5f3cac4c482984028ccf5235f455b8c984d977c71a0" dependencies = [ "byteorder", "criterion", @@ -333,9 +333,9 @@ dependencies = [ [[package]] name = "frost-ed25519" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "100cbe9e495922d9c381c4a9baf7341c6666f413227ec27cff3557f07dafe5ca" +checksum = "c190b586c268a320b683a6b57aa4b1a73176d85ecd69b0dbcb2e2786a034c8d3" dependencies = [ "curve25519-dalek", "frost-core", @@ -481,9 +481,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.141" +version = "0.2.142" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" +checksum = "6a987beff54b60ffa6d51982e1aa1146bc42f19bd26be28b0586f252fccf5317" [[package]] name = "libm" @@ -499,9 +499,9 @@ checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb" [[package]] name = "linux-raw-sys" -version = "0.3.1" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59d8c75012853d2e872fb56bc8a2e53718e2cafe1a4c823143141c6d90c322f" +checksum = "36eb31c1778188ae1e64398743890d0877fef36d11521ac60406b42016e8c2cf" [[package]] name = "log" @@ -615,7 +615,7 @@ version = "0.4.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" dependencies = [ - "unicode-xid 0.1.0", + "unicode-xid", ] [[package]] @@ -642,7 +642,7 @@ dependencies = [ "rand", "rand_chacha", "rand_xorshift", - "regex-syntax", + "regex-syntax 0.6.29", "rusty-fork", "tempfile", "unarray", @@ -761,11 +761,11 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.3" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d" +checksum = "af83e617f331cc6ae2da5443c602dfa5af81e517212d9d611a5b3ba1777b5370" dependencies = [ - "regex-syntax", + "regex-syntax 0.7.1", ] [[package]] @@ -774,11 +774,17 @@ version = "0.6.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" +[[package]] +name = "regex-syntax" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5996294f19bd3aae0453a862ad728f60e6600695733dd5df01da90c54363a3c" + [[package]] name = "rustix" -version = "0.37.11" +version = "0.37.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85597d61f83914ddeba6a47b3b8ffe7365107221c2e557ed94426489fefb5f77" +checksum = "d9b864d3c18a5785a05953adeed93e2dca37ed30f18e69bba9f30079d51f363f" dependencies = [ "bitflags", "errno", @@ -838,14 +844,14 @@ checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df" dependencies = [ "proc-macro2 1.0.56", "quote 1.0.26", - "syn 2.0.14", + "syn 2.0.15", ] [[package]] name = "serde_json" -version = "1.0.95" +version = "1.0.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d721eca97ac802aa7777b701877c8004d950fc142651367300d21c1cc0194744" +checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1" dependencies = [ "itoa", "ryu", @@ -877,7 +883,7 @@ checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" dependencies = [ "proc-macro2 0.4.30", "quote 0.6.13", - "unicode-xid 0.1.0", + "unicode-xid", ] [[package]] @@ -893,27 +899,15 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.14" +version = "2.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcf316d5356ed6847742d036f8a39c3b8435cac10bd528a4bd461928a6ab34d5" +checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822" dependencies = [ "proc-macro2 1.0.56", "quote 1.0.26", "unicode-ident", ] -[[package]] -name = "synstructure" -version = "0.12.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" -dependencies = [ - "proc-macro2 1.0.56", - "quote 1.0.26", - "syn 1.0.109", - "unicode-xid 0.2.4", -] - [[package]] name = "tempfile" version = "3.5.0" @@ -950,7 +944,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2 1.0.56", "quote 1.0.26", - "syn 2.0.14", + "syn 2.0.15", ] [[package]] @@ -987,12 +981,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - [[package]] name = "version_check" version = "0.9.4" @@ -1264,21 +1252,20 @@ checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" [[package]] name = "zeroize" -version = "1.5.7" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c394b5bd0c6f669e7275d9c20aa90ae064cb22e75a1cad54e1b34088034b149f" +checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" dependencies = [ "zeroize_derive", ] [[package]] name = "zeroize_derive" -version = "1.3.3" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44bf07cb3e50ea2003396695d58bf46bc9887a1f362260446fad6bc4e79bd36c" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2 1.0.56", "quote 1.0.26", - "syn 1.0.109", - "synstructure", + "syn 2.0.15", ] diff --git a/Cargo.toml b/Cargo.toml index 4ed6f18d..0b6332ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -frost-ed25519 = "0.1.0" +frost-ed25519 = "0.2.0" thiserror = "1.0" rand = "0.8" hex = "0.4" diff --git a/src/trusted_dealer_keygen.rs b/src/trusted_dealer_keygen.rs index 6ac71a5d..2d9f8273 100644 --- a/src/trusted_dealer_keygen.rs +++ b/src/trusted_dealer_keygen.rs @@ -13,11 +13,12 @@ pub fn trusted_dealer_keygen( let (shares, pubkeys) = frost::keys::keygen_with_dealer(config.max_signers, config.min_signers, rng).unwrap(); // TODO: handle error - let key_packages: HashMap<_, _> = shares - .into_iter() - .map(|share| Ok((share.identifier, frost::keys::KeyPackage::try_from(share)?))) - .collect::>() - .unwrap(); // TODO: handle error + let mut key_packages: HashMap<_, _> = HashMap::new(); + + for (k, v) in shares { + let key_package = frost::keys::KeyPackage::try_from(v).unwrap(); // TODO: handle error + key_packages.insert(k, key_package); + } (key_packages, pubkeys) } From b584b60461e804cbe8a1286c3460e9f08fac2855 Mon Sep 17 00:00:00 2001 From: natalie Date: Wed, 26 Apr 2023 15:18:55 +0100 Subject: [PATCH 10/12] Sort participants by identifier (#283) Improve error handling Add tests for output hex encode outputs --- Cargo.lock | 1 + Cargo.toml | 1 + src/inputs.rs | 17 +++---- src/main.rs | 38 +++------------- src/output.rs | 48 ++++++++++++++++++++ src/tests.rs | 1 + src/tests/output_tests.rs | 88 ++++++++++++++++++++++++++++++++++++ src/trusted_dealer_keygen.rs | 3 +- 8 files changed, 157 insertions(+), 40 deletions(-) create mode 100644 src/output.rs create mode 100644 src/tests/output_tests.rs diff --git a/Cargo.lock b/Cargo.lock index b63b3420..6f87c0a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -349,6 +349,7 @@ version = "0.1.0" dependencies = [ "frost-ed25519", "hex", + "itertools", "rand", "thiserror", ] diff --git a/Cargo.toml b/Cargo.toml index 0b6332ab..509441a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,3 +10,4 @@ frost-ed25519 = "0.2.0" thiserror = "1.0" rand = "0.8" hex = "0.4" +itertools = "0.10.5" diff --git a/src/inputs.rs b/src/inputs.rs index 43ce6d53..4194b424 100755 --- a/src/inputs.rs +++ b/src/inputs.rs @@ -23,17 +23,18 @@ pub fn validate_inputs(config: &Config) -> Result } pub fn request_inputs() -> Config { - let mut min = "".to_string(); + println!("The minimum number of signers: (2 or more)"); - println!("The minimum number of signers:"); - io::stdin().read_line(&mut min).unwrap(); // TODO: handle errors - let min_signers = min.trim().parse::().unwrap(); + let mut min = String::new(); + io::stdin().read_line(&mut min).expect("invalid input"); - let mut max = "".to_string(); + let min_signers = min.trim().parse::().expect("Invalid input"); - println!("The maximum number of signers:"); - io::stdin().read_line(&mut max).unwrap(); // TODO: handle errors - let max_signers = max.trim().parse::().unwrap(); + println!("The maximum number of signers: (must be greater than minimum number of signers)"); + + let mut max = String::new(); + io::stdin().read_line(&mut max).expect("invalid input"); + let max_signers = max.trim().parse::().expect("invalid input"); Config { min_signers, diff --git a/src/main.rs b/src/main.rs index 0db6f95d..da3729e2 100755 --- a/src/main.rs +++ b/src/main.rs @@ -3,51 +3,27 @@ mod inputs; mod tests; mod trusted_dealer_keygen; -use std::collections::HashMap; use std::io; -use frost_ed25519 as frost; - -use frost::keys::{KeyPackage, PublicKeyPackage}; -use frost::Identifier; +use output::{print_values, ConsoleLogger}; use rand::thread_rng; +mod output; use crate::inputs::{request_inputs, validate_inputs}; use crate::trusted_dealer_keygen::trusted_dealer_keygen; fn main() -> io::Result<()> { - // TODO: error handling let config = request_inputs(); let mut rng = thread_rng(); - let out = validate_inputs(&config); + validate_inputs(&config).expect("An error occurred"); - match out { - Ok(_) => (), - Err(e) => println!("An error occurred: {e}"), - } + // Print outputs + let (key_packages, pubkeys) = trusted_dealer_keygen(config, &mut rng); - if out.is_ok() { - // Print outputs - let (key_packages, pubkeys) = trusted_dealer_keygen(config, &mut rng); + let mut console_logger = ConsoleLogger::default(); - print_values(key_packages, pubkeys); - } + print_values(&key_packages, pubkeys, &mut console_logger); Ok(()) } - -fn print_values(keys: HashMap, pubkeys: PublicKeyPackage) { - println!("Group public key: {:x?}", pubkeys.group_public.to_bytes()); - // Need to be able to extract value for VerifiableSecretSharingCommitment that isn't currently accessible - // println!("Commitment: {:x?}", shares[0].commitment[0]); - - println!("---"); - - for (k, v) in keys { - println!("Participant {:?}", k); - println!("Secret share: {:x?}", v.secret_share.to_bytes()); - println!("Public key: {:x?}", v.public.to_bytes()); - println!("---") - } -} diff --git a/src/output.rs b/src/output.rs new file mode 100644 index 00000000..410048a8 --- /dev/null +++ b/src/output.rs @@ -0,0 +1,48 @@ +use std::collections::HashMap; + +use frost_ed25519 as frost; + +use frost::keys::{KeyPackage, PublicKeyPackage}; +use frost::Identifier; +use itertools::Itertools; + +pub trait Logger { + fn log(&mut self, value: String); +} + +#[derive(Default)] +pub struct ConsoleLogger; + +impl Logger for ConsoleLogger { + fn log(&mut self, value: String) { + println!("{}", value); + } +} + +pub fn print_values( + keys: &HashMap, + pubkeys: PublicKeyPackage, + logger: &mut dyn Logger, +) { + logger.log(format!( + "Group public key: {:x?}", + hex::encode(pubkeys.group_public.to_bytes()) + )); + // Need to be able to extract value for VerifiableSecretSharingCommitment that isn't currently accessible + // println!("Commitment: {:x?}", shares[0].commitment[0]); + + println!("---"); + + for (k, v) in keys.iter().sorted_by_key(|x| x.0) { + logger.log(format!("Participant {:?}", k)); + logger.log(format!( + "Secret share: {:?}", + hex::encode(v.secret_share.to_bytes()) + )); + logger.log(format!( + "Public key: {:?}", + hex::encode(v.public.to_bytes()) + )); + println!("---") + } +} diff --git a/src/tests.rs b/src/tests.rs index 0d3354ba..de7a20a2 100755 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,2 +1,3 @@ mod inputs_tests; mod integration_test; +mod output_tests; diff --git a/src/tests/output_tests.rs b/src/tests/output_tests.rs new file mode 100644 index 00000000..c42ddade --- /dev/null +++ b/src/tests/output_tests.rs @@ -0,0 +1,88 @@ +use frost::Identifier; +use frost_ed25519 as frost; +use rand::thread_rng; + +use crate::inputs::Config; +use crate::output::{print_values, Logger}; +use crate::trusted_dealer_keygen; + +struct TestLogger(Vec); + +impl Logger for TestLogger { + fn log(&mut self, value: String) { + self.0.push(value); + } +} + +#[test] +fn check_output() { + let mut test_logger = TestLogger(Vec::new()); + let mut rng = thread_rng(); + let config = Config { + min_signers: 2, + max_signers: 3, + }; + let (key_packages, pubkeys) = trusted_dealer_keygen(config, &mut rng); + + print_values(&key_packages, pubkeys, &mut test_logger); + + let signer_1 = Identifier::try_from(1).unwrap(); + let signer_2 = Identifier::try_from(2).unwrap(); + let signer_3 = Identifier::try_from(3).unwrap(); + + assert_eq!( + test_logger.0[0], + format!( + "Group public key: \"{}\"", + hex::encode(&key_packages[&signer_1].group_public.to_bytes()) + ) + ); + + assert_eq!(test_logger.0[1], format!("Participant {:?}", signer_1)); + assert_eq!( + test_logger.0[2], + format!( + "Secret share: \"{}\"", + hex::encode(&key_packages[&signer_1].secret_share.to_bytes()) + ) + ); + assert_eq!( + test_logger.0[3], + format!( + "Public key: \"{}\"", + hex::encode(&key_packages[&signer_1].public.to_bytes()) + ) + ); + + assert_eq!(test_logger.0[4], format!("Participant {:?}", signer_2)); + assert_eq!( + test_logger.0[5], + format!( + "Secret share: \"{}\"", + hex::encode(&key_packages[&signer_2].secret_share.to_bytes()) + ) + ); + assert_eq!( + test_logger.0[6], + format!( + "Public key: \"{}\"", + hex::encode(&key_packages[&signer_2].public.to_bytes()) + ) + ); + + assert_eq!(test_logger.0[7], format!("Participant {:?}", signer_3)); + assert_eq!( + test_logger.0[8], + format!( + "Secret share: \"{}\"", + hex::encode(&key_packages[&signer_3].secret_share.to_bytes()) + ) + ); + assert_eq!( + test_logger.0[9], + format!( + "Public key: \"{}\"", + hex::encode(&key_packages[&signer_3].public.to_bytes()) + ) + ); +} diff --git a/src/trusted_dealer_keygen.rs b/src/trusted_dealer_keygen.rs index 2d9f8273..cfd0c5c0 100644 --- a/src/trusted_dealer_keygen.rs +++ b/src/trusted_dealer_keygen.rs @@ -11,7 +11,8 @@ pub fn trusted_dealer_keygen( rng: &mut ThreadRng, ) -> (HashMap, PublicKeyPackage) { let (shares, pubkeys) = - frost::keys::keygen_with_dealer(config.max_signers, config.min_signers, rng).unwrap(); // TODO: handle error + frost::keys::keygen_with_dealer(config.max_signers, config.min_signers, rng) + .expect("Error generating keys"); // TODO: handle error let mut key_packages: HashMap<_, _> = HashMap::new(); From 7738d105faff4308f142c1b8a88ea5c6c2ea9c1e Mon Sep 17 00:00:00 2001 From: natalie Date: Wed, 26 Apr 2023 16:31:19 +0100 Subject: [PATCH 11/12] Fix clippy errors (#283) --- src/tests/output_tests.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/tests/output_tests.rs b/src/tests/output_tests.rs index c42ddade..0884dab7 100644 --- a/src/tests/output_tests.rs +++ b/src/tests/output_tests.rs @@ -34,7 +34,7 @@ fn check_output() { test_logger.0[0], format!( "Group public key: \"{}\"", - hex::encode(&key_packages[&signer_1].group_public.to_bytes()) + hex::encode(key_packages[&signer_1].group_public.to_bytes()) ) ); @@ -43,14 +43,14 @@ fn check_output() { test_logger.0[2], format!( "Secret share: \"{}\"", - hex::encode(&key_packages[&signer_1].secret_share.to_bytes()) + hex::encode(key_packages[&signer_1].secret_share.to_bytes()) ) ); assert_eq!( test_logger.0[3], format!( "Public key: \"{}\"", - hex::encode(&key_packages[&signer_1].public.to_bytes()) + hex::encode(key_packages[&signer_1].public.to_bytes()) ) ); @@ -59,14 +59,14 @@ fn check_output() { test_logger.0[5], format!( "Secret share: \"{}\"", - hex::encode(&key_packages[&signer_2].secret_share.to_bytes()) + hex::encode(key_packages[&signer_2].secret_share.to_bytes()) ) ); assert_eq!( test_logger.0[6], format!( "Public key: \"{}\"", - hex::encode(&key_packages[&signer_2].public.to_bytes()) + hex::encode(key_packages[&signer_2].public.to_bytes()) ) ); @@ -75,14 +75,14 @@ fn check_output() { test_logger.0[8], format!( "Secret share: \"{}\"", - hex::encode(&key_packages[&signer_3].secret_share.to_bytes()) + hex::encode(key_packages[&signer_3].secret_share.to_bytes()) ) ); assert_eq!( test_logger.0[9], format!( "Public key: \"{}\"", - hex::encode(&key_packages[&signer_3].public.to_bytes()) + hex::encode(key_packages[&signer_3].public.to_bytes()) ) ); } From ebaf08073d27f08e287ed130a53301054a92e6fc Mon Sep 17 00:00:00 2001 From: natalie Date: Thu, 27 Apr 2023 14:02:13 +0100 Subject: [PATCH 12/12] Refactor ConsoleLogger to be implemented in main (#283) --- src/main.rs | 11 ++++++++++- src/output.rs | 9 --------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index da3729e2..11703e79 100755 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ mod trusted_dealer_keygen; use std::io; -use output::{print_values, ConsoleLogger}; +use output::{print_values, Logger}; use rand::thread_rng; mod output; @@ -27,3 +27,12 @@ fn main() -> io::Result<()> { Ok(()) } + +#[derive(Default)] +pub struct ConsoleLogger; + +impl Logger for ConsoleLogger { + fn log(&mut self, value: String) { + println!("{}", value); + } +} diff --git a/src/output.rs b/src/output.rs index 410048a8..effefa5e 100644 --- a/src/output.rs +++ b/src/output.rs @@ -10,15 +10,6 @@ pub trait Logger { fn log(&mut self, value: String); } -#[derive(Default)] -pub struct ConsoleLogger; - -impl Logger for ConsoleLogger { - fn log(&mut self, value: String) { - println!("{}", value); - } -} - pub fn print_values( keys: &HashMap, pubkeys: PublicKeyPackage,