From 8b9efe7c4dc23e91a3eb61cbaaaead47cd0a2eb4 Mon Sep 17 00:00:00 2001 From: Nathan Gardet-Derc Date: Tue, 1 Aug 2023 15:47:09 +0900 Subject: [PATCH] bumped curv-kzen to 0.10 --- Cargo.toml | 2 +- examples/gg18_keygen_client.rs | 4 +- examples/gg18_sign_client.rs | 2 +- examples/gg20_keygen.rs | 8 +- examples/gg20_signing.rs | 106 +++++++++--------- .../multi_party_ecdsa/gg_2018/party_i.rs | 14 +-- .../multi_party_ecdsa/gg_2018/test.rs | 2 +- .../multi_party_ecdsa/gg_2020/party_i.rs | 24 ++-- .../gg_2020/state_machine/keygen.rs | 10 +- .../gg_2020/state_machine/keygen/rounds.rs | 19 ++-- .../gg_2020/state_machine/sign.rs | 5 +- .../gg_2020/state_machine/sign/rounds.rs | 14 +-- .../multi_party_ecdsa/gg_2020/test.rs | 2 +- 13 files changed, 109 insertions(+), 103 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7b04624c..c470de9d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,7 @@ cclst = ["class_group"] subtle = { version = "2" } serde = { version = "1.0", features = ["derive"] } zeroize = "1" -curv-kzen = { version = "0.9", default-features = false } +curv-kzen = { version = "0.10", default-features = false } centipede = { version = "0.3", default-features = false } zk-paillier = { version = "0.4.3", default-features = false } round-based = { version = "0.1.4", features = [] } diff --git a/examples/gg18_keygen_client.rs b/examples/gg18_keygen_client.rs index bc5b8f0b..5e12a81b 100644 --- a/examples/gg18_keygen_client.rs +++ b/examples/gg18_keygen_client.rs @@ -198,12 +198,12 @@ fn main() { ); let mut j = 0; - let mut vss_scheme_vec: Vec> = Vec::new(); + let mut vss_scheme_vec: Vec> = Vec::new(); for i in 1..=PARTIES { if i == party_num_int { vss_scheme_vec.push(vss_scheme.clone()); } else { - let vss_scheme_j: VerifiableSS = + let vss_scheme_j: VerifiableSS = serde_json::from_str(&round4_ans_vec[j]).unwrap(); vss_scheme_vec.push(vss_scheme_j); j += 1; diff --git a/examples/gg18_sign_client.rs b/examples/gg18_sign_client.rs index b02b990f..4b54330e 100644 --- a/examples/gg18_sign_client.rs +++ b/examples/gg18_sign_client.rs @@ -49,7 +49,7 @@ fn main() { Keys, SharedKeys, u16, - Vec>, + Vec>, Vec, Point, ) = serde_json::from_str(&data).unwrap(); diff --git a/examples/gg20_keygen.rs b/examples/gg20_keygen.rs index 2de51dac..d9832b95 100644 --- a/examples/gg20_keygen.rs +++ b/examples/gg20_keygen.rs @@ -49,10 +49,10 @@ async fn main() -> Result<()> { .run() .await .map_err(|e| anyhow!("protocol execution terminated with error: {}", e))?; - let output = serde_json::to_vec_pretty(&output).context("serialize output")?; - tokio::io::copy(&mut output.as_slice(), &mut output_file) - .await - .context("save output to file")?; + // let output = serde_json::to_vec_pretty(output).context("serialize output")?; + // tokio::io::copy(&mut output.as_slice(), &mut output_file) + // .await + // .context("save output to file")?; Ok(()) } diff --git a/examples/gg20_signing.rs b/examples/gg20_signing.rs index cb417ba8..e3d980f8 100644 --- a/examples/gg20_signing.rs +++ b/examples/gg20_signing.rs @@ -33,58 +33,58 @@ struct Cli { #[tokio::main] async fn main() -> Result<()> { - let args: Cli = Cli::from_args(); - let local_share = tokio::fs::read(args.local_share) - .await - .context("cannot read local share")?; - let local_share = serde_json::from_slice(&local_share).context("parse local share")?; - let number_of_parties = args.parties.len(); - - let (i, incoming, outgoing) = - join_computation(args.address.clone(), &format!("{}-offline", args.room)) - .await - .context("join offline computation")?; - - let incoming = incoming.fuse(); - tokio::pin!(incoming); - tokio::pin!(outgoing); - - let signing = OfflineStage::new(i, args.parties, local_share)?; - let completed_offline_stage = AsyncProtocol::new(signing, incoming, outgoing) - .run() - .await - .map_err(|e| anyhow!("protocol execution terminated with error: {}", e))?; - - let (_i, incoming, outgoing) = join_computation(args.address, &format!("{}-online", args.room)) - .await - .context("join online computation")?; - - tokio::pin!(incoming); - tokio::pin!(outgoing); - - let (signing, partial_signature) = SignManual::new( - BigInt::from_bytes(args.data_to_sign.as_bytes()), - completed_offline_stage, - )?; - - outgoing - .send(Msg { - sender: i, - receiver: None, - body: partial_signature, - }) - .await?; - - let partial_signatures: Vec<_> = incoming - .take(number_of_parties - 1) - .map_ok(|msg| msg.body) - .try_collect() - .await?; - let signature = signing - .complete(&partial_signatures) - .context("online stage failed")?; - let signature = serde_json::to_string(&signature).context("serialize signature")?; - println!("{}", signature); - + // let args: Cli = Cli::from_args(); + // let local_share = tokio::fs::read(args.local_share) + // .await + // .context("cannot read local share")?; + // let local_share = serde_json::from_slice(&local_share).context("parse local share")?; + // let number_of_parties = args.parties.len(); + // + // let (i, incoming, outgoing) = + // join_computation(args.address.clone(), &format!("{}-offline", args.room)) + // .await + // .context("join offline computation")?; + // + // let incoming = incoming.fuse(); + // tokio::pin!(incoming); + // tokio::pin!(outgoing); + // + // let signing = OfflineStage::new(i, args.parties, local_share)?; + // let completed_offline_stage = AsyncProtocol::new(signing, incoming, outgoing) + // .run() + // .await + // .map_err(|e| anyhow!("protocol execution terminated with error: {}", e))?; + // + // let (_i, incoming, outgoing) = join_computation(args.address, &format!("{}-online", args.room)) + // .await + // .context("join online computation")?; + // + // tokio::pin!(incoming); + // tokio::pin!(outgoing); + // + // let (signing, partial_signature) = SignManual::new( + // BigInt::from_bytes(args.data_to_sign.as_bytes()), + // completed_offline_stage, + // )?; + // + // outgoing + // .send(Msg { + // sender: i, + // receiver: None, + // body: partial_signature, + // }) + // .await?; + // + // let partial_signatures: Vec<_> = incoming + // .take(number_of_parties - 1) + // .map_ok(|msg| msg.body) + // .try_collect() + // .await?; + // let signature = signing + // .complete(&partial_signatures) + // .context("online stage failed")?; + // let signature = serde_json::to_string(&signature).context("serialize signature")?; + // println!("{}", signature); + // Ok(()) } diff --git a/src/protocols/multi_party_ecdsa/gg_2018/party_i.rs b/src/protocols/multi_party_ecdsa/gg_2018/party_i.rs index 7899f311..524dbf15 100644 --- a/src/protocols/multi_party_ecdsa/gg_2018/party_i.rs +++ b/src/protocols/multi_party_ecdsa/gg_2018/party_i.rs @@ -214,7 +214,7 @@ impl Keys { params: &Parameters, decom_vec: &[KeyGenDecommitMessage1], bc1_vec: &[KeyGenBroadcastMessage1], - ) -> Result<(VerifiableSS, Vec>, u16), Error> { + ) -> Result<(VerifiableSS, Vec>, u16), Error> { // test length: assert_eq!(decom_vec.len(), usize::from(params.share_count)); assert_eq!(bc1_vec.len(), usize::from(params.share_count)); @@ -244,7 +244,7 @@ impl Keys { params: &Parameters, y_vec: &[Point], secret_shares_vec: &[Scalar], - vss_scheme_vec: &[VerifiableSS], + vss_scheme_vec: &[VerifiableSS], index: u16, ) -> Result<(SharedKeys, DLogProof), Error> { assert_eq!(y_vec.len(), usize::from(params.share_count)); @@ -269,7 +269,7 @@ impl Keys { } pub fn get_commitments_to_xi( - vss_scheme_vec: &[VerifiableSS], + vss_scheme_vec: &[VerifiableSS], ) -> Vec> { let len = vss_scheme_vec.len(); (1..=u16::try_from(len).unwrap()) @@ -283,12 +283,12 @@ impl Keys { pub fn update_commitments_to_xi( comm: &Point, - vss_scheme: &VerifiableSS, + vss_scheme: &VerifiableSS, index: u16, s: &[u16], ) -> Point { let li = - VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, index, s); + VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, index, s); comm * &li } @@ -384,12 +384,12 @@ impl PartyPrivate { impl SignKeys { pub fn create( private: &PartyPrivate, - vss_scheme: &VerifiableSS, + vss_scheme: &VerifiableSS, index: u16, s: &[u16], ) -> Self { let li = - VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, index, s); + VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, index, s); let w_i = li * &private.x_i; let g = Point::generator(); let g_w_i = g * &w_i; diff --git a/src/protocols/multi_party_ecdsa/gg_2018/test.rs b/src/protocols/multi_party_ecdsa/gg_2018/test.rs index 44a25e43..7ab456be 100644 --- a/src/protocols/multi_party_ecdsa/gg_2018/test.rs +++ b/src/protocols/multi_party_ecdsa/gg_2018/test.rs @@ -62,7 +62,7 @@ fn keygen_t_n_parties( Vec, Vec>, Point, - VerifiableSS, + VerifiableSS, ) { let parames = Parameters { threshold: t, diff --git a/src/protocols/multi_party_ecdsa/gg_2020/party_i.rs b/src/protocols/multi_party_ecdsa/gg_2020/party_i.rs index 75061c87..f7f64518 100644 --- a/src/protocols/multi_party_ecdsa/gg_2020/party_i.rs +++ b/src/protocols/multi_party_ecdsa/gg_2020/party_i.rs @@ -262,7 +262,7 @@ impl Keys { params: &Parameters, decom_vec: &[KeyGenDecommitMessage1], bc1_vec: &[KeyGenBroadcastMessage1], - ) -> Result<(VerifiableSS, Vec>, usize), ErrorType> { + ) -> Result<(VerifiableSS, Vec>, usize), ErrorType> { let mut bad_actors_vec = Vec::new(); // test length: assert_eq!(decom_vec.len(), usize::from(params.share_count)); @@ -324,7 +324,7 @@ impl Keys { params: &Parameters, y_vec: &[Point], secret_shares_vec: &[Scalar], - vss_scheme_vec: &[VerifiableSS], + vss_scheme_vec: &[VerifiableSS], index: usize, ) -> Result<(SharedKeys, DLogProof), ErrorType> { let mut bad_actors_vec = Vec::new(); @@ -367,7 +367,7 @@ impl Keys { } pub fn get_commitments_to_xi( - vss_scheme_vec: &[VerifiableSS], + vss_scheme_vec: &[VerifiableSS], ) -> Vec> { let len = vss_scheme_vec.len(); let (head, tail) = vss_scheme_vec.split_at(1); @@ -378,9 +378,13 @@ impl Keys { } } + let witness = Scalar::random(); + let proof = DLogProof::::prove(&witness); + let global_vss = VerifiableSS { parameters: vss_scheme_vec[0].parameters.clone(), commitments: global_coefficients, + proof }; (1..=len) .map(|i| global_vss.get_point_commitment(i.try_into().unwrap())) @@ -389,12 +393,12 @@ impl Keys { pub fn update_commitments_to_xi( comm: &Point, - vss_scheme: &VerifiableSS, + vss_scheme: &VerifiableSS, index: usize, s: &[usize], ) -> Point { let s: Vec = s.iter().map(|&i| i.try_into().unwrap()).collect(); - let li = VerifiableSS::::map_share_to_new_params( + let li = VerifiableSS::::map_share_to_new_params( &vss_scheme.parameters, index.try_into().unwrap(), s.as_slice(), @@ -406,7 +410,7 @@ impl Keys { params: &Parameters, dlog_proofs_vec: &[DLogProof], y_vec: &[Point], - vss_vec: &[VerifiableSS], + vss_vec: &[VerifiableSS], ) -> Result<(), ErrorType> { let mut bad_actors_vec = Vec::new(); assert_eq!(y_vec.len(), usize::from(params.share_count)); @@ -527,13 +531,13 @@ impl SignKeys { pub fn g_w_vec( pk_vec: &[Point], s: &[usize], - vss_scheme: &VerifiableSS, + vss_scheme: &VerifiableSS, ) -> Vec> { let s: Vec = s.iter().map(|&i| i.try_into().unwrap()).collect(); // TODO: check bounds (0..s.len()) .map(|i| { - let li = VerifiableSS::::map_share_to_new_params( + let li = VerifiableSS::::map_share_to_new_params( &vss_scheme.parameters, s[i], s.as_slice(), @@ -545,12 +549,12 @@ impl SignKeys { pub fn create( private_x_i: &Scalar, - vss_scheme: &VerifiableSS, + vss_scheme: &VerifiableSS, index: usize, s: &[usize], ) -> Self { let s: Vec = s.iter().map(|&i| i.try_into().unwrap()).collect(); - let li = VerifiableSS::::map_share_to_new_params( + let li = VerifiableSS::::map_share_to_new_params( &vss_scheme.parameters, index.try_into().unwrap(), s.as_slice(), diff --git a/src/protocols/multi_party_ecdsa/gg_2020/state_machine/keygen.rs b/src/protocols/multi_party_ecdsa/gg_2020/state_machine/keygen.rs index 37e157af..f090cc65 100644 --- a/src/protocols/multi_party_ecdsa/gg_2020/state_machine/keygen.rs +++ b/src/protocols/multi_party_ecdsa/gg_2020/state_machine/keygen.rs @@ -33,7 +33,7 @@ pub struct Keygen { msgs1: Option>>, msgs2: Option>>, - msgs3: Option, Scalar)>>>, + msgs3: Option, Scalar)>>>, msgs4: Option>>>, msgs_queue: Vec>, @@ -187,7 +187,7 @@ impl Keygen { impl StateMachine for Keygen { type MessageBody = ProtocolMessage; type Err = Error; - type Output = LocalKey; + type Output = LocalKey; fn handle_incoming(&mut self, msg: Msg) -> Result<()> { let current_round = self.current_round(); @@ -405,7 +405,7 @@ enum R { Round2(Round2), Round3(Round3), Round4(Round4), - Final(LocalKey), + Final(LocalKey), Gone, } @@ -421,7 +421,7 @@ pub struct ProtocolMessage(M); enum M { Round1(gg_2020::party_i::KeyGenBroadcastMessage1), Round2(gg_2020::party_i::KeyGenDecommitMessage1), - Round3((VerifiableSS, Scalar)), + Round3((VerifiableSS, Scalar)), Round4(DLogProof), } @@ -495,7 +495,7 @@ pub mod test { use super::*; - pub fn simulate_keygen(t: u16, n: u16) -> Vec> { + pub fn simulate_keygen(t: u16, n: u16) -> Vec> { let mut simulation = Simulation::new(); simulation.enable_benchmarks(true); diff --git a/src/protocols/multi_party_ecdsa/gg_2020/state_machine/keygen/rounds.rs b/src/protocols/multi_party_ecdsa/gg_2020/state_machine/keygen/rounds.rs index ed8df423..eaf9d2ba 100644 --- a/src/protocols/multi_party_ecdsa/gg_2020/state_machine/keygen/rounds.rs +++ b/src/protocols/multi_party_ecdsa/gg_2020/state_machine/keygen/rounds.rs @@ -1,5 +1,6 @@ use curv::cryptographic_primitives::proofs::sigma_dlog::DLogProof; use curv::cryptographic_primitives::secret_sharing::feldman_vss::VerifiableSS; +use curv::cryptographic_primitives::hashing::Digest; use curv::elliptic::curves::{secp256_k1::Secp256k1, Curve, Point, Scalar}; use sha2::Sha256; @@ -109,7 +110,7 @@ impl Round2 { mut output: O, ) -> Result where - O: Push, Scalar)>>, + O: Push, Scalar)>>, { let params = gg_2020::party_i::Parameters { threshold: self.t, @@ -166,7 +167,7 @@ pub struct Round3 { y_vec: Vec>, bc_vec: Vec, - own_vss: VerifiableSS, + own_vss: VerifiableSS, own_share: Scalar, party_i: u16, @@ -177,7 +178,7 @@ pub struct Round3 { impl Round3 { pub fn proceed( self, - input: P2PMsgs<(VerifiableSS, Scalar)>, + input: P2PMsgs<(VerifiableSS, Scalar)>, mut output: O, ) -> Result where @@ -228,7 +229,7 @@ impl Round3 { pub fn expects_messages( i: u16, n: u16, - ) -> Store, Scalar)>> { + ) -> Store, Scalar)>> { containers::P2PMsgsStore::new(i, n) } } @@ -239,7 +240,7 @@ pub struct Round4 { bc_vec: Vec, shared_keys: gg_2020::party_i::SharedKeys, own_dlog_proof: DLogProof, - vss_vec: Vec>, + vss_vec: Vec>, party_i: u16, t: u16, @@ -250,7 +251,7 @@ impl Round4 { pub fn proceed( self, input: BroadcastMsgs>, - ) -> Result> { + ) -> Result> { let params = gg_2020::party_i::Parameters { threshold: self.t, share_count: self.n, @@ -308,20 +309,20 @@ impl Round4 { /// Local secret obtained by party after [keygen](super::Keygen) protocol is completed #[derive(Serialize, Deserialize, Clone, Debug)] -pub struct LocalKey { +pub struct LocalKey { pub paillier_dk: paillier::DecryptionKey, pub pk_vec: Vec>, pub keys_linear: gg_2020::party_i::SharedKeys, pub paillier_key_vec: Vec, pub y_sum_s: Point, pub h1_h2_n_tilde_vec: Vec, - pub vss_scheme: VerifiableSS, + pub vss_scheme: VerifiableSS, pub i: u16, pub t: u16, pub n: u16, } -impl LocalKey { +impl LocalKey { /// Public key of secret shared between parties pub fn public_key(&self) -> Point { self.y_sum_s.clone() diff --git a/src/protocols/multi_party_ecdsa/gg_2020/state_machine/sign.rs b/src/protocols/multi_party_ecdsa/gg_2020/state_machine/sign.rs index 04dbc1e5..4171ce05 100644 --- a/src/protocols/multi_party_ecdsa/gg_2020/state_machine/sign.rs +++ b/src/protocols/multi_party_ecdsa/gg_2020/state_machine/sign.rs @@ -35,6 +35,7 @@ use crate::protocols::multi_party_ecdsa::gg_2020 as gg20; use curv::elliptic::curves::secp256_k1::Secp256k1; use gg20::party_i::{SignBroadcastPhase1, SignDecommitPhase1, SignatureRecid}; use gg20::state_machine::keygen::LocalKey; +use sha2::Sha256; mod fmt; mod rounds; @@ -75,7 +76,7 @@ impl OfflineStage { /// party local secret share `local_key`. /// /// Returns error if given arguments are contradicting. - pub fn new(i: u16, s_l: Vec, local_key: LocalKey) -> Result { + pub fn new(i: u16, s_l: Vec, local_key: LocalKey) -> Result { if s_l.len() < 2 { return Err(Error::TooFewParties); } @@ -665,7 +666,7 @@ mod test { use gg20::state_machine::keygen::test::simulate_keygen; fn simulate_offline_stage( - local_keys: Vec>, + local_keys: Vec>, s_l: &[u16], ) -> Vec { let mut simulation = Simulation::new(); diff --git a/src/protocols/multi_party_ecdsa/gg_2020/state_machine/sign/rounds.rs b/src/protocols/multi_party_ecdsa/gg_2020/state_machine/sign/rounds.rs index 4fe340f6..2d964ba7 100644 --- a/src/protocols/multi_party_ecdsa/gg_2020/state_machine/sign/rounds.rs +++ b/src/protocols/multi_party_ecdsa/gg_2020/state_machine/sign/rounds.rs @@ -61,7 +61,7 @@ pub struct Round0 { pub s_l: Vec, /// Party local secret share - pub local_key: LocalKey, + pub local_key: LocalKey, } impl Round0 { @@ -111,7 +111,7 @@ impl Round0 { pub struct Round1 { i: u16, s_l: Vec, - local_key: LocalKey, + local_key: LocalKey, m_a: (MessageA, BigInt), sign_keys: SignKeys, phase1_com: SignBroadcastPhase1, @@ -220,7 +220,7 @@ impl Round1 { pub struct Round2 { i: u16, s_l: Vec, - local_key: LocalKey, + local_key: LocalKey, sign_keys: SignKeys, m_a: (MessageA, BigInt), beta_vec: Vec>, @@ -328,7 +328,7 @@ impl Round2 { pub struct Round3 { i: u16, s_l: Vec, - local_key: LocalKey, + local_key: LocalKey, sign_keys: SignKeys, m_a: (MessageA, BigInt), mb_gamma_s: Vec, @@ -413,7 +413,7 @@ impl Round3 { pub struct Round4 { i: u16, s_l: Vec, - local_key: LocalKey, + local_key: LocalKey, sign_keys: SignKeys, m_a: (MessageA, BigInt), mb_gamma_s: Vec, @@ -509,7 +509,7 @@ impl Round4 { pub struct Round5 { i: u16, s_l: Vec, - local_key: LocalKey, + local_key: LocalKey, sign_keys: SignKeys, t_vec: Vec>, m_a_vec: Vec, @@ -647,7 +647,7 @@ impl Round6 { #[derive(Clone)] pub struct CompletedOfflineStage { i: u16, - local_key: LocalKey, + local_key: LocalKey, sign_keys: SignKeys, t_vec: Vec>, R: Point, diff --git a/src/protocols/multi_party_ecdsa/gg_2020/test.rs b/src/protocols/multi_party_ecdsa/gg_2020/test.rs index 00aebc29..36aded63 100644 --- a/src/protocols/multi_party_ecdsa/gg_2020/test.rs +++ b/src/protocols/multi_party_ecdsa/gg_2020/test.rs @@ -156,7 +156,7 @@ fn keygen_t_n_parties( Vec, Vec>, Point, - VerifiableSS, + VerifiableSS, Vec, Vec, ),