diff --git a/coordinator/src/tests/steps.rs b/coordinator/src/tests/steps.rs index 163217ca..b96e9d45 100644 --- a/coordinator/src/tests/steps.rs +++ b/coordinator/src/tests/steps.rs @@ -1,107 +1,109 @@ -// // Test values from https://github.com/ZcashFoundation/frost/blob/main/frost-ed25519/tests/helpers/vectors.json - -// // // Input required: -// // // 1. public key package -// // // 2. number of signparticipantsers -// // // 3. identifiers for all signers -// // #[test] -// // fn check_step_1() { - -// // } - -// // // Input required: -// // // 1. message -// // // 2. number of signers -// // // 3. commitments for all signers -// // #[test] -// // fn check_step_2() { -// // } - -// use frost_ed25519 as frost; -// use std::{ -// collections::{BTreeMap, HashMap}, -// io::BufWriter, -// }; -// use frost::{ -// keys::{PublicKeyPackage, VerifyingShare}, -// round1::{NonceCommitment, SigningCommitments}, -// Identifier, SigningPackage, VerifyingKey, -// }; -// use crate::{step_1::ParticipantsConfig, step_3::step_3}; -// use hex::FromHex; - -// // // Input required: -// // // 1. number of signers (TODO: maybe pass this in?) -// // // 2. signatures for all signers +// Test values from https://github.com/ZcashFoundation/frost/blob/main/frost-ed25519/tests/helpers/vectors.json + +// // Input required: +// // 1. public key package +// // 2. number of signparticipantsers +// // 3. identifiers for all signers // #[test] -// fn check_step_3() { -// let mut buf = BufWriter::new(Vec::new()); - -// let id_1 = Identifier::try_from(1).unwrap(); -// let id_3 = Identifier::try_from(3).unwrap(); - -// const PUBLIC_KEY_1: &str = "fc2c9b8e335c132d9ebe0403c9317aac480bbbf8cbdb1bc3730bb68eb60dadf9"; -// const PUBLIC_KEY_3: &str = "2cff4148a2f965801fb1f25f1d2a4e5df2f75b3a57cd06f30471c2c774419a41"; -// const GROUP_PUBLIC_KEY: &str = -// "15d21ccd7ee42959562fc8aa63224c8851fb3ec85a3faf66040d380fb9738673"; - -// let mut signer_pubkeys = HashMap::new(); -// signer_pubkeys.insert( -// id_1, -// VerifyingShare::deserialize(<[u8; 32]>::from_hex(PUBLIC_KEY_1).unwrap()).unwrap(), -// ); -// signer_pubkeys.insert( -// id_3, -// VerifyingShare::deserialize(<[u8; 32]>::from_hex(PUBLIC_KEY_3).unwrap()).unwrap(), -// ); - -// let group_public = VerifyingKey::from_hex(GROUP_PUBLIC_KEY).unwrap(); - -// let signature_1 = "{\"share\":\"b97409beff18861f0959530db091a64b812e3fefaa87e1e3d2c039f11d96cc09\",\"ciphersuite\":\"FROST(Ed25519, SHA-512)\"}"; -// let signature_3 = "{\"share\":\"9816a14e7cdecfcb240976f564cf98c5640e596b6ddf270379efbef4e9f7db0b\",\"ciphersuite\":\"FROST(Ed25519, SHA-512)\"}"; - -// let input = format!("{}\n{}\n", signature_1, signature_3); - -// let mut valid_input = input.as_bytes(); - -// let participants_config = ParticipantsConfig { -// participants: vec![id_1, id_3], -// pub_key_package: PublicKeyPackage::new(signer_pubkeys, group_public), -// }; -// const HIDING_COMMITMENT_1: &str = -// "5078f5c6d679654bb88a8887242d49cc21a553ed26caed4d52570c6656fb9b92"; -// const BINDING_COMMITMENT_1: &str = -// "936b660d3008d8298b0a7220a327a0813ffedd9d07604bdc73d7cffef63c0da0"; -// const HIDING_COMMITMENT_3: &str = -// "91c2469b501fe5af8493f9ae77c8f57999460af317f2d9f2d4378ae0e665860e"; -// const BINDING_COMMITMENT_3: &str = -// "c225618accff2266a45d87dc3219b04c774ca26c8629c4fa483e7e87da820007"; - -// let signer_commitments_1 = SigningCommitments::new( -// NonceCommitment::deserialize(<[u8; 32]>::from_hex(HIDING_COMMITMENT_1).unwrap()).unwrap(), -// NonceCommitment::deserialize(<[u8; 32]>::from_hex(BINDING_COMMITMENT_1).unwrap()).unwrap(), -// ); -// let signer_commitments_3 = SigningCommitments::new( -// NonceCommitment::deserialize(<[u8; 32]>::from_hex(HIDING_COMMITMENT_3).unwrap()).unwrap(), -// NonceCommitment::deserialize(<[u8; 32]>::from_hex(BINDING_COMMITMENT_3).unwrap()).unwrap(), -// ); - -// let mut signing_commitments = BTreeMap::new(); -// signing_commitments.insert(id_1, signer_commitments_1); -// signing_commitments.insert(id_3, signer_commitments_3); - -// let signing_package = SigningPackage::new(signing_commitments, b"Iamamessage"); - -// // expect group sig: "72c948a63797c693e8e978fdb703a1f5a7590472a539da13b71dd6c2b8c1b2a664b7b4af6194439357c5d15f366760fce53c985a186709e74bb0f8e5078ea805" - -// step_3( -// &mut valid_input, -// &mut buf, -// participants_config, -// signing_package, -// ); - -// println!("{:?}", buf); - -// assert!(1 == 1) +// fn check_step_1() { // } + +// // Input required: +// // 1. message +// // 2. number of signers +// // 3. commitments for all signers +// #[test] +// fn check_step_2() { +// } + +use crate::{step_1::ParticipantsConfig, step_3::step_3}; +use frost::{ + keys::{PublicKeyPackage, VerifyingShare}, + round1::{NonceCommitment, SigningCommitments}, + Identifier, SigningPackage, VerifyingKey, +}; +use frost_ed25519 as frost; +use hex::FromHex; +use std::{ + collections::{BTreeMap, HashMap}, + io::BufWriter, +}; + +// // Input required: +// // 1. number of signers (TODO: maybe pass this in?) +// // 2. signatures for all signers +#[test] +fn check_step_3() { + let mut buf = BufWriter::new(Vec::new()); + + let id_1 = Identifier::try_from(1).unwrap(); + let id_3 = Identifier::try_from(3).unwrap(); + + const PUBLIC_KEY_1: &str = "fc2c9b8e335c132d9ebe0403c9317aac480bbbf8cbdb1bc3730bb68eb60dadf9"; + const PUBLIC_KEY_3: &str = "2cff4148a2f965801fb1f25f1d2a4e5df2f75b3a57cd06f30471c2c774419a41"; + const GROUP_PUBLIC_KEY: &str = + "15d21ccd7ee42959562fc8aa63224c8851fb3ec85a3faf66040d380fb9738673"; + + let mut signer_pubkeys = HashMap::new(); + signer_pubkeys.insert( + id_1, + VerifyingShare::deserialize(<[u8; 32]>::from_hex(PUBLIC_KEY_1).unwrap()).unwrap(), + ); + signer_pubkeys.insert( + id_3, + VerifyingShare::deserialize(<[u8; 32]>::from_hex(PUBLIC_KEY_3).unwrap()).unwrap(), + ); + + let group_public = VerifyingKey::from_hex(GROUP_PUBLIC_KEY).unwrap(); + + let signature_1 = "{\"share\":\"b97409beff18861f0959530db091a64b812e3fefaa87e1e3d2c039f11d96cc09\",\"ciphersuite\":\"FROST(Ed25519, SHA-512)\"}"; + let signature_3 = "{\"share\":\"9816a14e7cdecfcb240976f564cf98c5640e596b6ddf270379efbef4e9f7db0b\",\"ciphersuite\":\"FROST(Ed25519, SHA-512)\"}"; + + let input = format!("{}\n{}\n", signature_1, signature_3); + + let mut valid_input = input.as_bytes(); + + let participants_config = ParticipantsConfig { + participants: vec![id_1, id_3], + pub_key_package: PublicKeyPackage::new(signer_pubkeys, group_public), + }; + const HIDING_COMMITMENT_1: &str = + "5078f5c6d679654bb88a8887242d49cc21a553ed26caed4d52570c6656fb9b92"; + const BINDING_COMMITMENT_1: &str = + "936b660d3008d8298b0a7220a327a0813ffedd9d07604bdc73d7cffef63c0da0"; + const HIDING_COMMITMENT_3: &str = + "91c2469b501fe5af8493f9ae77c8f57999460af317f2d9f2d4378ae0e665860e"; + const BINDING_COMMITMENT_3: &str = + "c225618accff2266a45d87dc3219b04c774ca26c8629c4fa483e7e87da820007"; + + let signer_commitments_1 = SigningCommitments::new( + NonceCommitment::deserialize(<[u8; 32]>::from_hex(HIDING_COMMITMENT_1).unwrap()).unwrap(), + NonceCommitment::deserialize(<[u8; 32]>::from_hex(BINDING_COMMITMENT_1).unwrap()).unwrap(), + ); + let signer_commitments_3 = SigningCommitments::new( + NonceCommitment::deserialize(<[u8; 32]>::from_hex(HIDING_COMMITMENT_3).unwrap()).unwrap(), + NonceCommitment::deserialize(<[u8; 32]>::from_hex(BINDING_COMMITMENT_3).unwrap()).unwrap(), + ); + + let mut signing_commitments = BTreeMap::new(); + signing_commitments.insert(id_1, signer_commitments_1); + signing_commitments.insert(id_3, signer_commitments_3); + + let signing_package = SigningPackage::new(signing_commitments, b"test"); + + // expect group sig: "72c948a63797c693e8e978fdb703a1f5a7590472a539da13b71dd6c2b8c1b2a664b7b4af6194439357c5d15f366760fce53c985a186709e74bb0f8e5078ea805" + + step_3( + &mut valid_input, + &mut buf, + participants_config, + signing_package, + ); + + let expected = "The number of signers: 2\nPlease enter JSON encoded signatures for participant Identifier(\"0100000000000000000000000000000000000000000000000000000000000000\"):\nPlease enter JSON encoded signatures for participant Identifier(\"0300000000000000000000000000000000000000000000000000000000000000\"):\nGroup signature: \"72c948a63797c693e8e978fdb703a1f5a7590472a539da13b71dd6c2b8c1b2a664b7b4af6194439357c5d15f366760fce53c985a186709e74bb0f8e5078ea805\"\n"; + + let (_, res) = &buf.into_parts(); + let actual = hex::encode(res.as_ref().unwrap()); + + assert_eq!(hex::encode(expected), actual) +} diff --git a/coordinator/src/tests/values.md b/coordinator/src/tests/values.md index 52319759..884b40a5 100644 --- a/coordinator/src/tests/values.md +++ b/coordinator/src/tests/values.md @@ -3,7 +3,7 @@ Public key package: ``` -{"signer_pubkeys":{"0200000000000000000000000000000000000000000000000000000000000000":"ea7cf3846c3b640f437b7c3a942b86aea6df1856f37ea2960fa1cf0a21a69882", "0300000000000000000000000000000000000000000000000000000000000000":"9c9879ea25578cd0ea40aadea10bcba5517c2395632725c435ae72d35df60950", "0400000000000000000000000000000000000000000000000000000000000000":"307710ce34951ff47aa47fdf96390880af147f8fd84473a6ec275502113e81ab", "0100000000000000000000000000000000000000000000000000000000000000":"8432dc3f96a6758786095a129cecf4c514a74b8deaec32be9aac461c8eb94e28"}, "group_public":"ab317922217f089775976d07fdaded8b39ffc646a1e1559c657f26ad426014ce","ciphersuite":"FROST(Ed25519, SHA-512)"} +{"signer_pubkeys":{"0100000000000000000000000000000000000000000000000000000000000000":"fc2c9b8e335c132d9ebe0403c9317aac480bbbf8cbdb1bc3730bb68eb60dadf9", "0300000000000000000000000000000000000000000000000000000000000000":"2cff4148a2f965801fb1f25f1d2a4e5df2f75b3a57cd06f30471c2c774419a41", "0200000000000000000000000000000000000000000000000000000000000000":"f7c3031debffbaf121022409d057e6e1034a532636301d12e26beddff58d05c7"}, "group_public":"15d21ccd7ee42959562fc8aa63224c8851fb3ec85a3faf66040d380fb9738673", "ciphersuite":"FROST(Ed25519, SHA-512)"} ``` num of participants: @@ -14,41 +14,52 @@ num of participants: Identifier for participant 1: ``` -0200000000000000000000000000000000000000000000000000000000000000 +"0100000000000000000000000000000000000000000000000000000000000000" ``` -Identifier for participant 2: +Identifier for participant 3: ``` -0400000000000000000000000000000000000000000000000000000000000000 +"0300000000000000000000000000000000000000000000000000000000000000" ``` Message to be signed: ``` -9c9879ea25578cd0ea40aadea10bcba5517c2395632725c435ae72d35df60950 +9c9879ea25578cd0ea40aadea10bcba5517c2395632725c435ae ``` Commitment for Identifier 1: ``` -{"hiding": "9c9879ea25578cd0ea40aadea10bcba5517c2395632725c435ae72d35df60950", "binding": "9c9879ea25578cd0ea40aadea10bcba5517c2395632725c435ae72d35df60950", "ciphersuite":"FROST(Ed25519, SHA-512)" } +{"hiding": "5078f5c6d679654bb88a8887242d49cc21a553ed26caed4d52570c6656fb9b92", "binding": "936b660d3008d8298b0a7220a327a0813ffedd9d07604bdc73d7cffef63c0da0", "ciphersuite":"FROST(Ed25519, SHA-512)" } ``` -Commitment for Identifier 2: +Commitment for Identifier 3: ``` -{"hiding":"9c9879ea25578cd0ea40aadea10bcba5517c2395632725c435ae72d35df60950","binding":"9c9879ea25578cd0ea40aadea10bcba5517c2395632725c435ae72d35df60950","ciphersuite":"FROST(Ed25519, SHA-512)"} +{"hiding":"91c2469b501fe5af8493f9ae77c8f57999460af317f2d9f2d4378ae0e665860e","binding":"c225618accff2266a45d87dc3219b04c774ca26c8629c4fa483e7e87da820007","ciphersuite":"FROST(Ed25519, SHA-512)"} ``` -Signing package: +Signing package (expected): ``` -{"signing_commitments":{"0200000000000000000000000000000000000000000000000000000000000000":{"hiding":"9c9879ea25578cd0ea40aadea10bcba5517c2395632725c435ae72d35df60950","binding":"9c9879ea25578cd0ea40aadea10bcba5517c2395632725c435ae72d35df60950","ciphersuite":"FROST(Ed25519, SHA-512)"},"0400000000000000000000000000000000000000000000000000000000000000":{"hiding":"9c9879ea25578cd0ea40aadea10bcba5517c2395632725c435ae72d35df60950","binding":"9c9879ea25578cd0ea40aadea10bcba5517c2395632725c435ae72d35df60950","ciphersuite":"FROST(Ed25519, SHA-512)"}},"message":"9c9879ea25578cd0ea40aadea10bcba5517c2395632725c435ae72d35df60950","ciphersuite":"FROST(Ed25519, SHA-512)"} +{"signing_commitments":{"0100000000000000000000000000000000000000000000000000000000000000":{"hiding":"5078f5c6d679654bb88a8887242d49cc21a553ed26caed4d52570c6656fb9b92","binding":"936b660d3008d8298b0a7220a327a0813ffedd9d07604bdc73d7cffef63c0da0","ciphersuite":"FROST(Ed25519, SHA-512)"},"0300000000000000000000000000000000000000000000000000000000000000":{"hiding":"91c2469b501fe5af8493f9ae77c8f57999460af317f2d9f2d4378ae0e665860e","binding":"c225618accff2266a45d87dc3219b04c774ca26c8629c4fa483e7e87da820007","ciphersuite":"FROST(Ed25519, SHA-512)"}},"message":"74657374","ciphersuite":"FROST(Ed25519, SHA-512)"} ``` +Signature share for ID 1: -Signature share: +``` +{"share":"b97409beff18861f0959530db091a64b812e3fefaa87e1e3d2c039f11d96cc09","ciphersuite":"FROST(Ed25519, SHA-512)"} +``` + +Signature share for ID 2: + +``` +{"share":"9816a14e7cdecfcb240976f564cf98c5640e596b6ddf270379efbef4e9f7db0b","ciphersuite":"FROST(Ed25519, SHA-512)"} +``` + +Group signature share (expected): ``` -{"share":"a0a6cd1cca1fdfc9c2a81bc741ecc38cf16f30200fc7b906b854b4e3bd462602","ciphersuite":"FROST(Ed25519, SHA-512)"} +"72c948a63797c693e8e978fdb703a1f5a7590472a539da13b71dd6c2b8c1b2a664b7b4af6194439357c5d15f366760fce53c985a186709e74bb0f8e5078ea805" ``` \ No newline at end of file