From 480c5c10ff57e945828daff56ccda9838625287e Mon Sep 17 00:00:00 2001 From: natalie Date: Wed, 24 May 2023 15:37:43 +0100 Subject: [PATCH 1/5] Import split function from library (#362) Update frost-ed25519 to v0.3.0 Fix typo in README command --- Cargo.lock | 167 ++++++++++++++++------------------ Cargo.toml | 2 +- README.md | 2 +- src/inputs.rs | 5 + src/tests/integration_test.rs | 19 +++- src/trusted_dealer_keygen.rs | 6 +- 6 files changed, 108 insertions(+), 93 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1066f70..602b4cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -57,9 +57,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.12.1" +version = "3.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b1ce199063694f33ffb7dd4e0ee620741495c32833cde5aa08f02a0bf96f0c8" +checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" [[package]] name = "byteorder" @@ -87,9 +87,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "ciborium" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0c137568cc60b904a7724001b35ce2630fd00d5d84805fbb608ab89509d788f" +checksum = "effd91f6c78e5a4ace8a5d3c0b6bfaec9e2baaef55f3efc00e45fb2e477ee926" dependencies = [ "ciborium-io", "ciborium-ll", @@ -98,15 +98,15 @@ dependencies = [ [[package]] name = "ciborium-io" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "346de753af073cc87b52b2083a506b38ac176a44cfb05497b622e27be899b369" +checksum = "cdf919175532b369853f5d5e20b26b43112613fd6fe7aee757e35f7a44642656" [[package]] name = "ciborium-ll" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213030a2b5a4e0c0892b6652260cf6ccac84827b83a85a534e178e3906c4cf1b" +checksum = "defaa24ecc093c77630e6c15e17c51f5e187bf35ee514f4e2d67baaa96dae22b" dependencies = [ "ciborium-io", "half", @@ -114,9 +114,9 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.23" +version = "3.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" +checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" dependencies = [ "bitflags", "clap_lex", @@ -255,9 +255,9 @@ checksum = "f400d0750c0c069e8493f2256cb4da6f604b6d2eeb69a0ca8863acde352f8400" [[package]] name = "digest" -version = "0.10.6" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", "crypto-common", @@ -319,9 +319,9 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "frost-core" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05b1dfe39cf39c73c9d2b5f3cac4c482984028ccf5235f455b8c984d977c71a0" +checksum = "e2329106b2265939420de478389a83ffd63a76ec86b306c6d78ea345a5efced3" dependencies = [ "byteorder", "criterion", @@ -339,9 +339,9 @@ dependencies = [ [[package]] name = "frost-ed25519" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c190b586c268a320b683a6b57aa4b1a73176d85ecd69b0dbcb2e2786a034c8d3" +checksum = "b749ea831d8e9205f6c8d912d5656c5d320b0bb1489b4b6fdd715941a1e8dd1a" dependencies = [ "curve25519-dalek", "frost-core", @@ -474,9 +474,9 @@ checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" [[package]] name = "js-sys" -version = "0.3.61" +version = "0.3.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" +checksum = "2f37a4a5928311ac501dee68b3c7613a1037d0edb30c8e5427bd832d55d1b790" dependencies = [ "wasm-bindgen", ] @@ -489,9 +489,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.142" +version = "0.2.144" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a987beff54b60ffa6d51982e1aa1146bc42f19bd26be28b0586f252fccf5317" +checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" [[package]] name = "libm" @@ -501,15 +501,15 @@ checksum = "7fc7aa29613bd6a620df431842069224d8bc9011086b1db4c0e0cd47fa03ec9a" [[package]] name = "libm" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb" +checksum = "f7012b1bbb0719e1097c47611d3898568c546d597c2e74d66f6087edd5233ff4" [[package]] name = "linux-raw-sys" -version = "0.3.4" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36eb31c1778188ae1e64398743890d0877fef36d11521ac60406b42016e8c2cf" +checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" [[package]] name = "log" @@ -536,7 +536,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ "autocfg", - "libm 0.2.6", + "libm 0.2.7", ] [[package]] @@ -628,25 +628,24 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.56" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" +checksum = "fa1fb82fc0c281dd9671101b66b771ebbe1eaf967b96ac8740dcba4b70005ca8" dependencies = [ "unicode-ident", ] [[package]] name = "proptest" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29f1b898011ce9595050a68e60f90bad083ff2987a695a42357134c8381fba70" +checksum = "4e35c06b98bf36aba164cc17cb25f7e232f5c4aeea73baa14b8a9f0d92dbfa65" dependencies = [ "bit-set", "bitflags", "byteorder", "lazy_static", "num-traits", - "quick-error 2.0.1", "rand", "rand_chacha", "rand_xorshift", @@ -673,12 +672,6 @@ 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" @@ -690,11 +683,11 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.26" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" +checksum = "8f4f29d145265ec1c483c7c654450edde0bfe043d3938d6972630663356d9500" dependencies = [ - "proc-macro2 1.0.56", + "proc-macro2 1.0.58", ] [[package]] @@ -769,11 +762,11 @@ dependencies = [ [[package]] name = "regex" -version = "1.8.1" +version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af83e617f331cc6ae2da5443c602dfa5af81e517212d9d611a5b3ba1777b5370" +checksum = "d1a59b5d8e97dee33696bf13c5ba8ab85341c002922fba050069326b9c498974" dependencies = [ - "regex-syntax 0.7.1", + "regex-syntax 0.7.2", ] [[package]] @@ -784,15 +777,15 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5996294f19bd3aae0453a862ad728f60e6600695733dd5df01da90c54363a3c" +checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" [[package]] name = "rustix" -version = "0.37.14" +version = "0.37.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b864d3c18a5785a05953adeed93e2dca37ed30f18e69bba9f30079d51f363f" +checksum = "acf8729d8542766f1b2cf77eb034d52f40d375bb8b615d0b147089946e16613d" dependencies = [ "bitflags", "errno", @@ -809,7 +802,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" dependencies = [ "fnv", - "quick-error 1.2.3", + "quick-error", "tempfile", "wait-timeout", ] @@ -837,22 +830,22 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.160" +version = "1.0.163" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c" +checksum = "2113ab51b87a539ae008b5c6c02dc020ffa39afd2d83cffcb3f4eb2722cebec2" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.160" +version = "1.0.163" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df" +checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e" dependencies = [ - "proc-macro2 1.0.56", - "quote 1.0.26", - "syn 2.0.15", + "proc-macro2 1.0.58", + "quote 1.0.27", + "syn 2.0.16", ] [[package]] @@ -900,19 +893,19 @@ version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ - "proc-macro2 1.0.56", - "quote 1.0.26", + "proc-macro2 1.0.58", + "quote 1.0.27", "unicode-ident", ] [[package]] name = "syn" -version = "2.0.15" +version = "2.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822" +checksum = "a6f671d4b5ffdb8eadec19c0ae67fe2639df8684bd7bc4b83d986b8db549cf01" dependencies = [ - "proc-macro2 1.0.56", - "quote 1.0.26", + "proc-macro2 1.0.58", + "quote 1.0.27", "unicode-ident", ] @@ -950,9 +943,9 @@ version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ - "proc-macro2 1.0.56", - "quote 1.0.26", - "syn 2.0.15", + "proc-macro2 1.0.58", + "quote 1.0.27", + "syn 2.0.16", ] [[package]] @@ -1001,8 +994,8 @@ version = "0.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8881d5cc0ae34e3db2f1de5af81e5117a420d2f937506c2dc20d6f4cfb069051" dependencies = [ - "proc-macro2 1.0.56", - "quote 1.0.26", + "proc-macro2 1.0.58", + "quote 1.0.27", "syn 1.0.109", ] @@ -1033,9 +1026,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.84" +version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" +checksum = "5bba0e8cb82ba49ff4e229459ff22a191bbe9a1cb3a341610c9c33efc27ddf73" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -1043,53 +1036,53 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.84" +version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" +checksum = "19b04bc93f9d6bdee709f6bd2118f57dd6679cf1176a1af464fca3ab0d66d8fb" dependencies = [ "bumpalo", "log", "once_cell", - "proc-macro2 1.0.56", - "quote 1.0.26", - "syn 1.0.109", + "proc-macro2 1.0.58", + "quote 1.0.27", + "syn 2.0.16", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.84" +version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" +checksum = "14d6b024f1a526bb0234f52840389927257beb670610081360e5a03c5df9c258" dependencies = [ - "quote 1.0.26", + "quote 1.0.27", "wasm-bindgen-macro-support", ] [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.84" +version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" +checksum = "e128beba882dd1eb6200e1dc92ae6c5dbaa4311aa7bb211ca035779e5efc39f8" dependencies = [ - "proc-macro2 1.0.56", - "quote 1.0.26", - "syn 1.0.109", + "proc-macro2 1.0.58", + "quote 1.0.27", + "syn 2.0.16", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.84" +version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" +checksum = "ed9d5b4305409d1fc9482fee2d7f9bcbf24b3972bf59817ef757e23982242a93" [[package]] name = "web-sys" -version = "0.3.61" +version = "0.3.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" +checksum = "3bdd9ef4e984da1187bf8110c5cf5b845fbc87a23602cdf912386a76fcd3a7c2" dependencies = [ "js-sys", "wasm-bindgen", @@ -1273,7 +1266,7 @@ version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ - "proc-macro2 1.0.56", - "quote 1.0.26", - "syn 2.0.15", + "proc-macro2 1.0.58", + "quote 1.0.27", + "syn 2.0.16", ] diff --git a/Cargo.toml b/Cargo.toml index ac13121..143ab0a 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.2.0" +frost-ed25519 = "0.3.0" thiserror = "1.0" rand = "0.8" hex = "0.4" diff --git a/README.md b/README.md index d40fb82..d312a3f 100755 --- a/README.md +++ b/README.md @@ -92,4 +92,4 @@ NOTE: A signer is a participant that generates a signing share which is aggregat Test coverage checks are performed in the pipeline. This is configured here: `.github/workflows/coverage.yaml` To run these locally: 1. Install coverage tool by running `cargo install cargo-llvm-cov` -2. Run `cargo cov` (you may be asked if you want to install `llvm-tools-preview`, if so type `Y`) +2. Run `cargo make cov` (you may be asked if you want to install `llvm-tools-preview`, if so type `Y`) diff --git a/src/inputs.rs b/src/inputs.rs index a576efb..9e57248 100755 --- a/src/inputs.rs +++ b/src/inputs.rs @@ -7,6 +7,11 @@ pub struct Config { pub max_signers: u16, } +pub struct _SecretConfig { + pub signers: Config, + pub secret: Vec, +} + pub fn validate_inputs(config: &Config) -> Result<(), Error> { if config.min_signers < 2 { return Err(Error::InvalidMinSigners); diff --git a/src/tests/integration_test.rs b/src/tests/integration_test.rs index f25987e..e85916c 100644 --- a/src/tests/integration_test.rs +++ b/src/tests/integration_test.rs @@ -1,12 +1,13 @@ -use crate::inputs::Config; +use crate::inputs::{Config, _SecretConfig}; use frost_ed25519 as frost; use rand::thread_rng; +use crate::trusted_dealer_keygen::_split; use crate::trusted_dealer_keygen::trusted_dealer_keygen; mod signature_gen; #[test] -fn check_keygen() { +fn check_keygen_with_dealer() { let mut rng = thread_rng(); let config = Config { min_signers: 2, @@ -26,3 +27,17 @@ fn check_keygen() { assert!(verify_signature.is_ok()); } + +#[test] +fn check_keygen_with_dealer_with_secret() { + let mut rng = thread_rng(); + let config = Config { + min_signers: 2, + max_signers: 3, + }; + let secret_config = _SecretConfig { + signers: config, + secret: b"byte".to_vec(), // Todo + }; + _split(secret_config, &mut rng); +} diff --git a/src/trusted_dealer_keygen.rs b/src/trusted_dealer_keygen.rs index 8e045a2..ac57e70 100644 --- a/src/trusted_dealer_keygen.rs +++ b/src/trusted_dealer_keygen.rs @@ -4,14 +4,14 @@ use frost_ed25519 as frost; use rand::rngs::ThreadRng; use std::collections::HashMap; -use crate::inputs::Config; +use crate::inputs::{Config, _SecretConfig}; pub fn trusted_dealer_keygen( config: Config, rng: &mut ThreadRng, ) -> Result<(HashMap, PublicKeyPackage), Error> { let (shares, pubkeys) = - frost::keys::keygen_with_dealer(config.max_signers, config.min_signers, rng)?; + frost::keys::generate_with_dealer(config.max_signers, config.min_signers, rng)?; let mut key_packages: HashMap<_, _> = HashMap::new(); @@ -22,3 +22,5 @@ pub fn trusted_dealer_keygen( Ok((key_packages, pubkeys)) } + +pub fn _split(_config: _SecretConfig, _rng: &mut ThreadRng) {} From 32bf470df58553dd01adb151f0b2b2222bd1657b Mon Sep 17 00:00:00 2001 From: natalie Date: Fri, 2 Jun 2023 16:54:55 +0100 Subject: [PATCH 2/5] Add input for secret (#362) --- src/inputs.rs | 24 +++++++++++++++--------- src/main.rs | 2 +- src/tests/inputs_tests.rs | 29 +++++++++++++++++++++++++---- src/tests/integration_test.rs | 16 +++++++--------- src/tests/output_tests.rs | 5 +++-- src/trusted_dealer_keygen.rs | 6 +++--- 6 files changed, 54 insertions(+), 28 deletions(-) diff --git a/src/inputs.rs b/src/inputs.rs index 9e57248..5ef1bb3 100755 --- a/src/inputs.rs +++ b/src/inputs.rs @@ -1,15 +1,12 @@ -use frost_ed25519::Error; +use frost::Error; +use frost_ed25519 as frost; use std::io::BufRead; -#[derive(Debug, PartialEq, Copy, Clone)] +#[derive(Debug, PartialEq, Clone)] pub struct Config { pub min_signers: u16, pub max_signers: u16, -} - -pub struct _SecretConfig { - pub signers: Config, - pub secret: Vec, + pub secret: Vec, // todo } pub fn validate_inputs(config: &Config) -> Result<(), Error> { @@ -48,8 +45,17 @@ pub fn request_inputs(input: &mut impl BufRead) -> Result { .parse::() .map_err(|_| Error::InvalidMaxSigners)?; - Ok(Config { + println!("Secret key (if you don't have one then press enter): "); + + let mut secret_input = String::new(); + input.read_line(&mut secret_input).unwrap(); + let secret = hex::decode(secret_input.trim()).map_err(|_| Error::MalformedSigningKey)?; + + let config = Config { min_signers, max_signers, - }) + secret, + }; + + Ok(config) } diff --git a/src/main.rs b/src/main.rs index 2856d65..ccc5171 100755 --- a/src/main.rs +++ b/src/main.rs @@ -31,7 +31,7 @@ fn main() -> io::Result<()> { } // Print outputs - let out = trusted_dealer_keygen(config, &mut rng); + let out = trusted_dealer_keygen(&config, &mut rng); if let Err(e) = out { eprintln!("Error: {}", e); std::process::exit(1) diff --git a/src/tests/inputs_tests.rs b/src/tests/inputs_tests.rs index 0f647fc..a0ac473 100755 --- a/src/tests/inputs_tests.rs +++ b/src/tests/inputs_tests.rs @@ -5,6 +5,7 @@ fn check_valid_input_for_signers() { let config = Config { min_signers: 2, max_signers: 3, + secret: Vec::new(), }; let expected = validate_inputs(&config); @@ -17,6 +18,7 @@ fn return_error_if_min_participant_greater_than_max_participant() { let config = Config { min_signers: 4, max_signers: 3, + secret: Vec::new(), }; let expected = validate_inputs(&config); @@ -29,6 +31,7 @@ fn return_error_if_min_participant_is_less_than_2() { let config = Config { min_signers: 1, max_signers: 3, + secret: Vec::new(), }; let expected = validate_inputs(&config); @@ -41,6 +44,7 @@ fn return_error_if_max_participant_is_less_than_2() { let config = Config { min_signers: 2, max_signers: 1, + secret: Vec::new(), }; let expected = validate_inputs(&config); @@ -48,13 +52,22 @@ fn return_error_if_max_participant_is_less_than_2() { assert_eq!(expected, Err(frost_ed25519::Error::InvalidMaxSigners)); } +// Testing inclusion of secret input + #[test] -fn return_config_if_valid_input() { - let mut valid_input = "3\n6\n".as_bytes(); +fn check_valid_input_with_secret() { + let mut valid_input = + "3\n6\n7b1c33d3f5291d85de664833beb1ad469f7fb6025a0ec78b3a790c6e13a98304\n".as_bytes(); let config = request_inputs(&mut valid_input).unwrap(); + + let secret: Vec = vec![ + 123, 28, 51, 211, 245, 41, 29, 133, 222, 102, 72, 51, 190, 177, 173, 70, 159, 127, 182, 2, + 90, 14, 199, 139, 58, 121, 12, 110, 19, 169, 131, 4, + ]; let expected = Config { min_signers: 3, max_signers: 6, + secret, }; assert_eq!(expected, config) @@ -62,7 +75,7 @@ fn return_config_if_valid_input() { #[test] fn return_error_if_invalid_min_signers_input() { - let mut invalid_input = "hello\n6\n".as_bytes(); + let mut invalid_input = "hello\n6\n\n".as_bytes(); let expected = request_inputs(&mut invalid_input); assert_eq!(expected, Err(frost_ed25519::Error::InvalidMinSigners)) @@ -70,8 +83,16 @@ fn return_error_if_invalid_min_signers_input() { #[test] fn return_error_if_invalid_max_signers_input() { - let mut invalid_input = "4\nworld\n".as_bytes(); + let mut invalid_input = "4\nworld\n\n".as_bytes(); let expected = request_inputs(&mut invalid_input); assert_eq!(expected, Err(frost_ed25519::Error::InvalidMaxSigners)) } + +#[test] +fn return_error_if_secret_is_invalid() { + let mut secret_input = "4\n6\nasecret\n".as_bytes(); + let expected = request_inputs(&mut secret_input); + + assert_eq!(expected, Err(frost_ed25519::Error::MalformedSigningKey)) +} diff --git a/src/tests/integration_test.rs b/src/tests/integration_test.rs index e85916c..423f2da 100644 --- a/src/tests/integration_test.rs +++ b/src/tests/integration_test.rs @@ -1,8 +1,8 @@ -use crate::inputs::{Config, _SecretConfig}; +use crate::inputs::Config; use frost_ed25519 as frost; use rand::thread_rng; -use crate::trusted_dealer_keygen::_split; +use crate::trusted_dealer_keygen::_split_secret; use crate::trusted_dealer_keygen::trusted_dealer_keygen; mod signature_gen; @@ -12,8 +12,9 @@ fn check_keygen_with_dealer() { let config = Config { min_signers: 2, max_signers: 3, + secret: Vec::new(), }; - let (key_packages, pubkeys) = trusted_dealer_keygen(config, &mut rng).unwrap(); + let (key_packages, pubkeys) = trusted_dealer_keygen(&config, &mut rng).unwrap(); let (nonces, commitments) = signature_gen::generate_nonces_and_commitments(config.min_signers, &key_packages, &mut rng); let message = "message to sign".as_bytes(); @@ -31,13 +32,10 @@ fn check_keygen_with_dealer() { #[test] fn check_keygen_with_dealer_with_secret() { let mut rng = thread_rng(); - let config = Config { + let secret_config = Config { min_signers: 2, max_signers: 3, + secret: b"byte".to_vec(), }; - let secret_config = _SecretConfig { - signers: config, - secret: b"byte".to_vec(), // Todo - }; - _split(secret_config, &mut rng); + _split_secret(secret_config, &mut rng); } diff --git a/src/tests/output_tests.rs b/src/tests/output_tests.rs index 978b26d..73721dc 100644 --- a/src/tests/output_tests.rs +++ b/src/tests/output_tests.rs @@ -4,7 +4,7 @@ use rand::thread_rng; use crate::inputs::Config; use crate::output::{print_values, Logger}; -use crate::trusted_dealer_keygen; +use crate::trusted_dealer_keygen::trusted_dealer_keygen; struct TestLogger(Vec); @@ -21,8 +21,9 @@ fn check_output() { let config = Config { min_signers: 2, max_signers: 3, + secret: Vec::new(), }; - let (key_packages, pubkeys) = trusted_dealer_keygen(config, &mut rng).unwrap(); + let (key_packages, pubkeys) = trusted_dealer_keygen(&config, &mut rng).unwrap(); print_values(&key_packages, pubkeys, &mut test_logger); diff --git a/src/trusted_dealer_keygen.rs b/src/trusted_dealer_keygen.rs index ac57e70..f66bf7c 100644 --- a/src/trusted_dealer_keygen.rs +++ b/src/trusted_dealer_keygen.rs @@ -4,10 +4,10 @@ use frost_ed25519 as frost; use rand::rngs::ThreadRng; use std::collections::HashMap; -use crate::inputs::{Config, _SecretConfig}; +use crate::inputs::Config; pub fn trusted_dealer_keygen( - config: Config, + config: &Config, rng: &mut ThreadRng, ) -> Result<(HashMap, PublicKeyPackage), Error> { let (shares, pubkeys) = @@ -23,4 +23,4 @@ pub fn trusted_dealer_keygen( Ok((key_packages, pubkeys)) } -pub fn _split(_config: _SecretConfig, _rng: &mut ThreadRng) {} +pub fn _split_secret(_config: Config, _rng: &mut ThreadRng) {} From bc987bbba8b44a7e87461920850a09a8ee910652 Mon Sep 17 00:00:00 2001 From: natalie Date: Mon, 5 Jun 2023 11:25:43 +0100 Subject: [PATCH 3/5] Add functionality for split_secret when a secret has been provided (#362) --- src/main.rs | 20 ++++++--- src/tests/integration_test.rs | 25 +++++++++-- src/tests/output_tests.rs | 82 ++++++++++++++++++++++++++++++++++- src/trusted_dealer_keygen.rs | 20 ++++++++- 4 files changed, 133 insertions(+), 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index ccc5171..222ba76 100755 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ use std::io; use output::{print_values, Logger}; use rand::thread_rng; +use trusted_dealer_keygen::split_secret; mod output; use crate::inputs::{request_inputs, validate_inputs}; @@ -30,14 +31,19 @@ fn main() -> io::Result<()> { std::process::exit(exitcode::DATAERR) } - // Print outputs - let out = trusted_dealer_keygen(&config, &mut rng); - if let Err(e) = out { - eprintln!("Error: {}", e); - std::process::exit(1) - } + let keygen = if config.secret.is_empty() { + trusted_dealer_keygen(&config, &mut rng).unwrap() + } else { + split_secret(&config, &mut rng) + }; - let (key_packages, pubkeys) = out.unwrap(); + // Print outputs + // if let Err(e) = keygen { + // eprintln!("Error: {}", e); + // std::process::exit(1) + // } + + let (key_packages, pubkeys) = keygen; let mut console_logger = ConsoleLogger::default(); diff --git a/src/tests/integration_test.rs b/src/tests/integration_test.rs index 423f2da..4b5da92 100644 --- a/src/tests/integration_test.rs +++ b/src/tests/integration_test.rs @@ -1,8 +1,8 @@ use crate::inputs::Config; +use crate::trusted_dealer_keygen::split_secret; use frost_ed25519 as frost; use rand::thread_rng; -use crate::trusted_dealer_keygen::_split_secret; use crate::trusted_dealer_keygen::trusted_dealer_keygen; mod signature_gen; @@ -32,10 +32,29 @@ fn check_keygen_with_dealer() { #[test] fn check_keygen_with_dealer_with_secret() { let mut rng = thread_rng(); + let secret: Vec = vec![ + 123, 28, 51, 211, 245, 41, 29, 133, 222, 102, 72, 51, 190, 177, 173, 70, 159, 127, 182, 2, + 90, 14, 199, 139, 58, 121, 12, 110, 19, 169, 131, 4, + ]; let secret_config = Config { min_signers: 2, max_signers: 3, - secret: b"byte".to_vec(), + secret, }; - _split_secret(secret_config, &mut rng); + let (key_packages, pubkeys) = split_secret(&secret_config, &mut rng); + let (nonces, commitments) = signature_gen::generate_nonces_and_commitments( + secret_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/tests/output_tests.rs b/src/tests/output_tests.rs index 73721dc..3951c39 100644 --- a/src/tests/output_tests.rs +++ b/src/tests/output_tests.rs @@ -4,7 +4,7 @@ use rand::thread_rng; use crate::inputs::Config; use crate::output::{print_values, Logger}; -use crate::trusted_dealer_keygen::trusted_dealer_keygen; +use crate::trusted_dealer_keygen::{split_secret, trusted_dealer_keygen}; struct TestLogger(Vec); @@ -15,7 +15,7 @@ impl Logger for TestLogger { } #[test] -fn check_output() { +fn check_output_without_secret() { let mut test_logger = TestLogger(Vec::new()); let mut rng = thread_rng(); let config = Config { @@ -87,3 +87,81 @@ fn check_output() { ) ); } + +#[test] +fn check_output_with_secret() { + let mut test_logger = TestLogger(Vec::new()); + let mut rng = thread_rng(); + let secret: Vec = vec![ + 123, 28, 51, 211, 245, 41, 29, 133, 222, 102, 72, 51, 190, 177, 173, 70, 159, 127, 182, 2, + 90, 14, 199, 139, 58, 121, 12, 110, 19, 169, 131, 4, + ]; + let config = Config { + min_signers: 2, + max_signers: 3, + secret, + }; + let (key_packages, pubkeys) = split_secret(&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 f66bf7c..f26574a 100644 --- a/src/trusted_dealer_keygen.rs +++ b/src/trusted_dealer_keygen.rs @@ -1,5 +1,5 @@ use frost::keys::{KeyPackage, PublicKeyPackage}; -use frost::{Error, Identifier}; +use frost::{Error, Identifier, SigningKey}; use frost_ed25519 as frost; use rand::rngs::ThreadRng; use std::collections::HashMap; @@ -23,4 +23,20 @@ pub fn trusted_dealer_keygen( Ok((key_packages, pubkeys)) } -pub fn _split_secret(_config: Config, _rng: &mut ThreadRng) {} +pub fn split_secret( + config: &Config, + rng: &mut ThreadRng, +) -> (HashMap, PublicKeyPackage) { + let sec = config.secret.clone(); + let again = sec.try_into().unwrap(); + let secret_key = SigningKey::from_bytes(again).unwrap(); + let (shares, pubkeys) = + frost::keys::split(&secret_key, config.max_signers, config.min_signers, rng).unwrap(); + let mut key_packages: HashMap<_, _> = HashMap::new(); + + for (k, v) in shares { + let key_package = frost::keys::KeyPackage::try_from(v).unwrap(); + key_packages.insert(k, key_package); + } + (key_packages, pubkeys) +} From 2bba8bfa151a6e0308e32952fc33d4b565655419 Mon Sep 17 00:00:00 2001 From: natalie Date: Mon, 5 Jun 2023 11:40:59 +0100 Subject: [PATCH 4/5] Add error handling for split_secret (#362) --- src/main.rs | 12 ++++++------ src/tests/integration_test.rs | 2 +- src/tests/output_tests.rs | 2 +- src/trusted_dealer_keygen.rs | 10 +++++----- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index 222ba76..3e74705 100755 --- a/src/main.rs +++ b/src/main.rs @@ -32,18 +32,18 @@ fn main() -> io::Result<()> { } let keygen = if config.secret.is_empty() { - trusted_dealer_keygen(&config, &mut rng).unwrap() + trusted_dealer_keygen(&config, &mut rng) } else { split_secret(&config, &mut rng) }; // Print outputs - // if let Err(e) = keygen { - // eprintln!("Error: {}", e); - // std::process::exit(1) - // } + if let Err(e) = keygen { + eprintln!("Error: {}", e); + std::process::exit(1) + } - let (key_packages, pubkeys) = keygen; + let (key_packages, pubkeys) = keygen.unwrap(); let mut console_logger = ConsoleLogger::default(); diff --git a/src/tests/integration_test.rs b/src/tests/integration_test.rs index 4b5da92..9b5e756 100644 --- a/src/tests/integration_test.rs +++ b/src/tests/integration_test.rs @@ -41,7 +41,7 @@ fn check_keygen_with_dealer_with_secret() { max_signers: 3, secret, }; - let (key_packages, pubkeys) = split_secret(&secret_config, &mut rng); + let (key_packages, pubkeys) = split_secret(&secret_config, &mut rng).unwrap(); let (nonces, commitments) = signature_gen::generate_nonces_and_commitments( secret_config.min_signers, &key_packages, diff --git a/src/tests/output_tests.rs b/src/tests/output_tests.rs index 3951c39..73ceff7 100644 --- a/src/tests/output_tests.rs +++ b/src/tests/output_tests.rs @@ -101,7 +101,7 @@ fn check_output_with_secret() { max_signers: 3, secret, }; - let (key_packages, pubkeys) = split_secret(&config, &mut rng); + let (key_packages, pubkeys) = split_secret(&config, &mut rng).unwrap(); print_values(&key_packages, pubkeys, &mut test_logger); diff --git a/src/trusted_dealer_keygen.rs b/src/trusted_dealer_keygen.rs index f26574a..9fee1ec 100644 --- a/src/trusted_dealer_keygen.rs +++ b/src/trusted_dealer_keygen.rs @@ -26,17 +26,17 @@ pub fn trusted_dealer_keygen( pub fn split_secret( config: &Config, rng: &mut ThreadRng, -) -> (HashMap, PublicKeyPackage) { +) -> Result<(HashMap, PublicKeyPackage), Error> { let sec = config.secret.clone(); let again = sec.try_into().unwrap(); - let secret_key = SigningKey::from_bytes(again).unwrap(); + let secret_key = SigningKey::from_bytes(again)?; let (shares, pubkeys) = - frost::keys::split(&secret_key, config.max_signers, config.min_signers, rng).unwrap(); + frost::keys::split(&secret_key, config.max_signers, config.min_signers, rng)?; let mut key_packages: HashMap<_, _> = HashMap::new(); for (k, v) in shares { - let key_package = frost::keys::KeyPackage::try_from(v).unwrap(); + let key_package = frost::keys::KeyPackage::try_from(v)?; key_packages.insert(k, key_package); } - (key_packages, pubkeys) + Ok((key_packages, pubkeys)) } From 28359ee3e0def84c55ce07bb22c61d6713f9428b Mon Sep 17 00:00:00 2001 From: natalie Date: Mon, 5 Jun 2023 19:26:46 +0100 Subject: [PATCH 5/5] Update secret key input text Co-authored-by: Conrado Gouvea --- src/inputs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inputs.rs b/src/inputs.rs index 5ef1bb3..f5164c6 100755 --- a/src/inputs.rs +++ b/src/inputs.rs @@ -45,7 +45,7 @@ pub fn request_inputs(input: &mut impl BufRead) -> Result { .parse::() .map_err(|_| Error::InvalidMaxSigners)?; - println!("Secret key (if you don't have one then press enter): "); + println!("Secret key (press enter to randomly generate a fresh one): "); let mut secret_input = String::new(); input.read_line(&mut secret_input).unwrap();