Skip to content

Commit

Permalink
server: make it ciphersuite-generic (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
conradoplg authored Jun 19, 2024
1 parent 54f2c41 commit 1b0acb6
Show file tree
Hide file tree
Showing 9 changed files with 388 additions and 161 deletions.
4 changes: 3 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion coordinator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ tokio = { version = "1", features = ["full"] }
message-io = "0.18"

[features]
redpallas = ["server/redpallas"]
redpallas = []
default = []
28 changes: 20 additions & 8 deletions coordinator/src/comms/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,15 @@ impl Comms for HTTPComms {
};
eprintln!();

Ok(r.commitments
let commitments = r
.commitments
.first()
.ok_or(eyre!("empty commitments"))
.cloned()?)
.ok_or(eyre!("empty commitments"))?
.iter()
.map(|(i, c)| Ok((i.try_into()?, c.try_into()?)))
.collect::<Result<_, Box<dyn Error>>>()?;

Ok(commitments)
}

async fn get_signature_shares(
Expand All @@ -110,9 +115,11 @@ impl Comms for HTTPComms {
.json(&server::SendSigningPackageArgs {
aux_msg: Default::default(),
session_id: self.session_id.unwrap(),
signing_package: vec![signing_package.clone()],
signing_package: vec![signing_package.try_into()?],
#[cfg(feature = "redpallas")]
randomizer: vec![randomizer],
randomizer: vec![randomizer.into()],
#[cfg(not(feature = "redpallas"))]
randomizer: vec![],
})
.send()
.await?
Expand All @@ -139,9 +146,14 @@ impl Comms for HTTPComms {
};
eprintln!();

Ok(r.signature_shares
let signature_shares = r
.signature_shares
.first()
.ok_or(eyre!("empty signature shares"))?
.clone())
.ok_or(eyre!("empty signature_shares"))?
.iter()
.map(|(i, c)| Ok((i.try_into()?, c.try_into()?)))
.collect::<Result<_, Box<dyn Error>>>()?;

Ok(signature_shares)
}
}
36 changes: 18 additions & 18 deletions participant/src/comms/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ impl Comms for HTTPComms {
.post(format!("{}/send_commitments", self.host_port))
.json(&server::SendCommitmentsArgs {
session_id: self.session_id,
identifier,
commitments: vec![commitments],
identifier: identifier.into(),
commitments: vec![(&commitments).try_into()?],
})
.send()
.await?;
Expand Down Expand Up @@ -83,23 +83,23 @@ impl Comms for HTTPComms {
};

#[cfg(feature = "redpallas")]
let signing_package = (
r.signing_package
let signing_package = {
let signing_package = r
.signing_package
.first()
.ok_or(eyre!("missing signing package"))
.cloned()?,
r.randomizer
.first()
.ok_or(eyre!("missing randomizer"))
.cloned()?,
);
.ok_or(eyre!("missing signing package"))?;
let randomizer = r.randomizer.first().ok_or(eyre!("missing randomizer"))?;
(signing_package.try_into()?, randomizer.try_into()?)
};

#[cfg(not(feature = "redpallas"))]
let signing_package = r
.signing_package
.first()
.ok_or(eyre!("missing signing package"))
.cloned()?;
let signing_package = {
let signing_package = r
.signing_package
.first()
.ok_or(eyre!("missing signing package"))?;
signing_package.try_into()?
};

Ok(signing_package)
}
Expand All @@ -117,9 +117,9 @@ impl Comms for HTTPComms {
.client
.post(format!("{}/send_signature_share", self.host_port))
.json(&server::SendSignatureShareArgs {
identifier,
identifier: identifier.into(),
session_id: self.session_id,
signature_share: vec![signature_share],
signature_share: vec![signature_share.into()],
})
.send()
.await?;
Expand Down
15 changes: 8 additions & 7 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ axum = "0.7.5"
clap = { version = "4.5.4", features = ["derive"] }
derivative = "2.2.0"
eyre = "0.6.11"
frost-ed25519 = { version = "1.0.0-rc.0", features = ["serde"] }
frost-core = { version = "1.0.0-rc.0", features = ["serde"] }
frost-rerandomized = { version = "1.0.0-rc.0", features = ["serde"] }
rand = "0.8"
reddsa = { git = "https://github.com/ZcashFoundation/reddsa.git", rev = "81c649c412e5b6ba56d491d2857f91fbd28adbc7", features = [
"frost",
"serde",
] }
serde = { version = "1.0", features = ["derive"] }
serdect = { version = "0.2.0" }
serde_json = "1.0.117"
tokio = { version = "1.37", features = ["full"] }
tower-http = { version = "0.5.2", features = ["trace"] }
Expand All @@ -26,10 +24,13 @@ uuid = { version = "1.6.1", features = ["v4", "fast-rng", "serde"] }

[dev-dependencies]
axum-test = "14.10.0"
coordinator = { path = "../coordinator" }
frost-ed25519 = { version = "1.0.0-rc.0", features = ["serde"] }
reddsa = { git = "https://github.com/ZcashFoundation/reddsa.git", rev = "81c649c412e5b6ba56d491d2857f91fbd28adbc7", features = [
"frost",
"serde",
] }
reqwest = { version = "0.12.4", features = ["json"] }
regex = "1.10.4"

[features]
redpallas = ["coordinator/redpallas"]
default = []
21 changes: 9 additions & 12 deletions server/src/functions.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::BTreeSet;
use std::collections::HashSet;

use axum::{extract::State, http::StatusCode, Json};

Expand Down Expand Up @@ -107,7 +107,7 @@ pub(crate) async fn send_commitments(
}

/// Implement the get_commitments API
#[tracing::instrument(ret, err(Debug))]
// #[tracing::instrument(ret, err(Debug))]
pub(crate) async fn get_commitments(
State(state): State<SharedState>,
Json(args): Json<GetCommitmentsArgs>,
Expand All @@ -128,7 +128,7 @@ pub(crate) async fn get_commitments(
.map(|i| {
commitments
.iter()
.map(|(id, c)| (*id, c[i as usize]))
.map(|(id, c)| (id.clone(), c[i as usize].clone()))
.collect()
})
.collect(),
Expand Down Expand Up @@ -164,8 +164,9 @@ pub(crate) async fn send_signing_package(
eyre!("wrong number of inputs"),
));
}
#[cfg(feature = "redpallas")]
if args.randomizer.len() != session.message_count as usize {
if args.randomizer.len() != session.message_count as usize
&& !args.randomizer.is_empty()
{
return Err(AppError(
StatusCode::INTERNAL_SERVER_ERROR,
eyre!("wrong number of inputs"),
Expand All @@ -175,7 +176,6 @@ pub(crate) async fn send_signing_package(
identifiers: commitments.keys().cloned().collect(),
signing_package: args.signing_package,
signature_shares: Default::default(),
#[cfg(feature = "redpallas")]
randomizer: args.randomizer,
aux_msg: args.aux_msg,
};
Expand Down Expand Up @@ -208,12 +208,10 @@ pub(crate) async fn get_signing_package(
identifiers: _,
signing_package,
signature_shares: _,
#[cfg(feature = "redpallas")]
randomizer,
aux_msg,
} => Ok(Json(GetSigningPackageOutput {
signing_package: signing_package.clone(),
#[cfg(feature = "redpallas")]
randomizer: randomizer.clone(),
aux_msg: aux_msg.clone(),
})),
Expand Down Expand Up @@ -246,8 +244,7 @@ pub(crate) async fn send_signature_share(
identifiers,
signing_package: _,
signature_shares,
#[cfg(feature = "redpallas")]
randomizer: _,
randomizer: _,
aux_msg: _,
} => {
if !identifiers.contains(&args.identifier) {
Expand All @@ -264,7 +261,7 @@ pub(crate) async fn send_signature_share(
// poor networking connectivity leading to retries)
signature_shares.insert(args.identifier, args.signature_share);
// If complete, advance to next state
if signature_shares.keys().cloned().collect::<BTreeSet<_>>() == *identifiers {
if signature_shares.keys().cloned().collect::<HashSet<_>>() == *identifiers {
session.state = SessionState::SignatureSharesReady {
signature_shares: signature_shares.clone(),
};
Expand Down Expand Up @@ -303,7 +300,7 @@ pub(crate) async fn get_signature_shares(
.map(|i| {
signature_shares
.iter()
.map(|(id, s)| (*id, s[i as usize]))
.map(|(id, s)| (id.clone(), s[i as usize].clone()))
.collect()
})
.collect(),
Expand Down
36 changes: 18 additions & 18 deletions server/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use std::{
collections::{BTreeMap, BTreeSet, HashMap},
collections::{HashMap, HashSet},
sync::{Arc, RwLock},
};

#[cfg(not(feature = "redpallas"))]
use frost_ed25519 as frost;
#[cfg(feature = "redpallas")]
use reddsa::frost::redpallas as frost;

use uuid::Uuid;

use crate::{
SerializedIdentifier, SerializedSignatureShare, SerializedSigningCommitments,
SerializedSigningPackage,
};

use crate::SerializedRandomizer;

/// The current state of the server, and the required data for the state.
#[derive(derivative::Derivative)]
#[derivative(Debug)]
Expand All @@ -18,41 +20,39 @@ pub enum SessionState {
WaitingForCommitments {
/// Commitments sent by participants so far, for each message being
/// signed.
commitments: BTreeMap<frost::Identifier, Vec<frost::round1::SigningCommitments>>,
commitments: HashMap<SerializedIdentifier, Vec<SerializedSigningCommitments>>,
},
/// Commitments have been sent by all participants; ready to be fetched by
/// the coordinator. Waiting for coordinator to send the SigningPackage.
CommitmentsReady {
/// All commitments sent by participants, for each message being signed.
commitments: BTreeMap<frost::Identifier, Vec<frost::round1::SigningCommitments>>,
commitments: HashMap<SerializedIdentifier, Vec<SerializedSigningCommitments>>,
},
/// SigningPackage ready to be fetched by participants. Waiting for
/// participants to send their signature shares.
WaitingForSignatureShares {
/// Identifiers of the participants that sent commitments in the
/// previous state.
identifiers: BTreeSet<frost::Identifier>,
identifiers: HashSet<SerializedIdentifier>,
/// SigningPackage sent by the coordinator to be sent to participants,
/// for each message being signed.
signing_package: Vec<frost::SigningPackage>,
signing_package: Vec<SerializedSigningPackage>,
/// Randomizer sent by coordinator to be sent to participants, for each
/// message being signed.
/// (Rerandomized FROST only. TODO: make it optional?)
#[cfg(feature = "redpallas")]
#[cfg_attr(feature = "redpallas", derivative(Debug = "ignore"))]
randomizer: Vec<frost::round2::Randomizer>,
/// message being signed. Can be empty if not being used.
#[derivative(Debug = "ignore")]
randomizer: Vec<SerializedRandomizer>,
/// Auxiliary (optional) message. A context-specific data that is
/// supposed to be interpreted by the participants.
aux_msg: Vec<u8>,
/// Signature shares sent by participants so far, for each message being
/// signed.
signature_shares: BTreeMap<frost::Identifier, Vec<frost::round2::SignatureShare>>,
signature_shares: HashMap<SerializedIdentifier, Vec<SerializedSignatureShare>>,
},
/// SignatureShares have been sent by all participants; ready to be fetched
/// by the coordinator.
SignatureSharesReady {
/// Signature shares sent by participants, for each message being signed.
signature_shares: BTreeMap<frost::Identifier, Vec<frost::round2::SignatureShare>>,
signature_shares: HashMap<SerializedIdentifier, Vec<SerializedSignatureShare>>,
},
}

Expand All @@ -70,7 +70,7 @@ pub struct Session {
/// The number of signers in the session.
pub(crate) num_signers: u16,
/// The set of identifiers for the session.
// pub(crate) identifiers: BTreeSet<frost::Identifier>,
// pub(crate) identifiers: BTreeSet<SerializedIdentifier>,
/// The number of messages being simultaneously signed.
pub(crate) message_count: u8,
/// The session state.
Expand Down
Loading

0 comments on commit 1b0acb6

Please sign in to comment.