Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phase 1 cleanup #138

Merged
merged 5 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
with:
persist-credentials: false

- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/rust-toolchain@stable
with:
components: llvm-tools-preview

Expand Down
11 changes: 4 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@ on:

jobs:

# We're using nightly for the async traits.
# TODO: Revert back to stable when that is stabilized.

test_ed25519:
name: Test with ed25519
runs-on: ubuntu-latest

steps:
- uses: actions/[email protected]
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/rust-toolchain@stable
- run: cargo test

test_redpallas:
Expand All @@ -28,7 +25,7 @@ jobs:

steps:
- uses: actions/[email protected]
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/rust-toolchain@stable
- run: cargo test --features redpallas

clippy:
Expand All @@ -39,7 +36,7 @@ jobs:
- uses: actions/[email protected]
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Run clippy manually without annotations
Expand All @@ -53,7 +50,7 @@ jobs:
- uses: actions/[email protected]
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- uses: Swatinem/rust-cache@v2
Expand Down
13 changes: 13 additions & 0 deletions 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 @@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
async-trait = "0.1.77"
eyre = "0.6.12"
frost-ed25519 = { version = "1.0.0-rc.0", features = ["serde"] }
reddsa = { git = "https://github.com/ZcashFoundation/reddsa.git", rev = "81c649c412e5b6ba56d491d2857f91fbd28adbc7", features = ["frost", "serde"] }
Expand All @@ -21,5 +22,4 @@ message-io = "0.18"

[features]
redpallas = []
sockets = []
default = []
6 changes: 6 additions & 0 deletions coordinator/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ use clap::Parser;
#[derive(Parser, Debug, Default)]
#[command(author, version, about, long_about = None)]
pub struct Args {
/// CLI mode. If enabled, it will prompt for inputs from stdin
/// and print values to stdout, ignoring other flags.
/// If false, socket communication is enabled.
#[arg(long, default_value_t = false)]
pub cli: bool,

/// The number of participants. If 0, will prompt for a value.
#[arg(short = 'n', long, default_value_t = 0)]
pub num_signers: u16,
Expand Down
17 changes: 8 additions & 9 deletions coordinator/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::io::{BufRead, Write};

use crate::args::Args;
#[cfg(not(feature = "sockets"))]
use crate::comms::cli::CLIComms;
#[cfg(feature = "sockets")]
use crate::comms::socket::SocketComms;
use crate::comms::Comms;
use crate::step_1::step_1;
use crate::step_2::step_2;
use crate::step_3::step_3;
Expand All @@ -19,13 +18,13 @@ pub async fn cli(
) -> Result<(), Box<dyn std::error::Error>> {
writeln!(logger, "\n=== STEP 1: CHOOSE PARTICIPANTS ===\n")?;

#[cfg(not(feature = "sockets"))]
let mut comms = CLIComms {};
let mut comms: Box<dyn Comms> = if args.cli {
Box::new(CLIComms {})
} else {
Box::new(SocketComms::new(args))
};

#[cfg(feature = "sockets")]
let mut comms = SocketComms::new(&args);

let participants_config = step_1(args, &mut comms, reader, logger).await?;
let participants_config = step_1(args, &mut *comms, reader, logger).await?;

writeln!(
logger,
Expand All @@ -47,7 +46,7 @@ pub async fn cli(

step_3(
args,
&mut comms,
&mut *comms,
reader,
logger,
participants_config,
Expand Down
16 changes: 9 additions & 7 deletions coordinator/src/comms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ use frost_ed25519 as frost;
#[cfg(feature = "redpallas")]
use reddsa::frost::redpallas as frost;

use std::{
collections::BTreeMap,
error::Error,
io::{BufRead, Write},
};

use async_trait::async_trait;

use frost::{
keys::PublicKeyPackage,
round1::SigningCommitments,
Expand All @@ -14,12 +22,6 @@ use frost::{
Identifier, SigningPackage,
};

use std::{
collections::BTreeMap,
error::Error,
io::{BufRead, Write},
};

#[derive(Serialize, Deserialize)]
#[serde(crate = "self::serde")]
#[allow(clippy::large_enum_variant)]
Expand All @@ -32,7 +34,7 @@ pub enum Message {
SignatureShare(SignatureShare),
}

#[allow(async_fn_in_trait)]
#[async_trait(?Send)]
pub trait Comms {
async fn get_signing_commitments(
&mut self,
Expand Down
3 changes: 3 additions & 0 deletions coordinator/src/comms/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use reddsa::frost::redpallas as frost;

use eyre::eyre;

use async_trait::async_trait;

use frost::{
keys::PublicKeyPackage, round1::SigningCommitments, round2::SignatureShare, Identifier,
SigningPackage,
Expand All @@ -22,6 +24,7 @@ use super::Comms;

pub struct CLIComms {}

#[async_trait(?Send)]
impl Comms for CLIComms {
async fn get_signing_commitments(
&mut self,
Expand Down
2 changes: 2 additions & 0 deletions coordinator/src/comms/socket.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Socket implementation of the Comms trait, using message-io.

use async_trait::async_trait;
#[cfg(not(feature = "redpallas"))]
use frost_ed25519 as frost;
#[cfg(feature = "redpallas")]
Expand Down Expand Up @@ -71,6 +72,7 @@ impl SocketComms {
}
}

#[async_trait(?Send)]
impl Comms for SocketComms {
async fn get_signing_commitments(
&mut self,
Expand Down
6 changes: 3 additions & 3 deletions coordinator/src/step_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct ParticipantsConfig {
// TODO: needs to include the coordinator's keys!
pub async fn step_1(
args: &Args,
comms: &mut impl Comms,
comms: &mut dyn Comms,
reader: &mut dyn BufRead,
logger: &mut dyn Write,
) -> Result<ParticipantsConfig, Box<dyn std::error::Error>> {
Expand All @@ -38,7 +38,7 @@ pub async fn step_1(
// 3. identifiers for all participants
async fn read_commitments(
args: &Args,
comms: &mut impl Comms,
comms: &mut dyn Comms,
input: &mut dyn BufRead,
logger: &mut dyn Write,
) -> Result<ParticipantsConfig, Box<dyn std::error::Error>> {
Expand All @@ -50,7 +50,7 @@ async fn read_commitments(
)?;
let pub_key_package: PublicKeyPackage = serde_json::from_str(&pub_key_package)?;

let num_of_participants = if args.num_signers == 0 {
let num_of_participants = if args.cli && args.num_signers == 0 {
writeln!(logger, "The number of participants: ")?;

let mut participants = String::new();
Expand Down
2 changes: 1 addition & 1 deletion coordinator/src/step_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn request_message(
logger: &mut dyn Write,
commitments: BTreeMap<Identifier, SigningCommitments>,
) -> Result<SigningPackage, Box<dyn std::error::Error>> {
let message = if args.message == "-" {
let message = if args.cli && args.message == "-" {
writeln!(logger, "The message to be signed (hex encoded)")?;

let mut msg = String::new();
Expand Down
4 changes: 2 additions & 2 deletions coordinator/src/step_3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn request_randomizer(

pub async fn step_3(
args: &Args,
comms: &mut impl Comms,
comms: &mut dyn Comms,
input: &mut dyn BufRead,
logger: &mut dyn Write,
participants: ParticipantsConfig,
Expand All @@ -56,7 +56,7 @@ pub async fn step_3(
// 1. number of signers (TODO: maybe pass this in?)
// 2. signatures for all signers
async fn request_inputs_signature_shares(
comms: &mut impl Comms,
comms: &mut dyn Comms,
input: &mut dyn BufRead,
logger: &mut dyn Write,
participants: ParticipantsConfig,
Expand Down
2 changes: 1 addition & 1 deletion participant/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
async-trait = "0.1.77"
frost-ed25519 = { version = "1.0.0-rc.0", features = ["serde"] }
reddsa = { git = "https://github.com/ZcashFoundation/reddsa.git", rev = "81c649c412e5b6ba56d491d2857f91fbd28adbc7", features = ["frost"] }
hex = "0.4"
Expand All @@ -19,5 +20,4 @@ message-io = "0.18"

[features]
redpallas = []
sockets = []
default = []
6 changes: 6 additions & 0 deletions participant/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ use clap::Parser;
#[derive(Parser, Debug, Default)]
#[command(author, version, about, long_about = None)]
pub struct Args {
/// CLI mode. If enabled, it will prompt for inputs from stdin
/// and print values to stdout, ignoring other flags.
/// If false, socket communication is enabled.
#[arg(long, default_value_t = false)]
pub cli: bool,

/// Public key package to use. Can be a file with a JSON-encoded
/// package, or "-". If the file does not exist or if "-" is specified,
/// then it will be read from standard input.
Expand Down
14 changes: 6 additions & 8 deletions participant/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::args::Args;

#[cfg(not(feature = "sockets"))]
use crate::comms::cli::CLIComms;
#[cfg(feature = "sockets")]
use crate::comms::socket::SocketComms;

use crate::comms::Comms;
Expand All @@ -17,11 +15,11 @@ pub async fn cli(
input: &mut impl BufRead,
logger: &mut impl Write,
) -> Result<(), Box<dyn std::error::Error>> {
#[cfg(not(feature = "sockets"))]
let mut comms = CLIComms {};

#[cfg(feature = "sockets")]
let mut comms = SocketComms::new(&args);
let mut comms: Box<dyn Comms> = if args.cli {
Box::new(CLIComms {})
} else {
Box::new(SocketComms::new(args))
};

// Round 1

Expand All @@ -38,7 +36,7 @@ pub async fn cli(
// Round 2 - Sign

let round_2_config = round_2_request_inputs(
&mut comms,
&mut *comms,
input,
logger,
commitments,
Expand Down
4 changes: 3 additions & 1 deletion participant/src/comms.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
pub mod cli;
pub mod socket;

use async_trait::async_trait;

#[cfg(not(feature = "redpallas"))]
use frost_ed25519 as frost;
#[cfg(feature = "redpallas")]
Expand Down Expand Up @@ -30,7 +32,7 @@ pub enum Message {
SignatureShare(SignatureShare),
}

#[allow(async_fn_in_trait)]
#[async_trait(?Send)]
pub trait Comms {
async fn get_signing_package(
&mut self,
Expand Down
2 changes: 2 additions & 0 deletions participant/src/comms/cli.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Command line interface implementation of the Comms trait.

use async_trait::async_trait;
#[cfg(not(feature = "redpallas"))]
use frost_ed25519 as frost;
#[cfg(feature = "redpallas")]
Expand All @@ -22,6 +23,7 @@ use crate::comms::Comms;

pub struct CLIComms {}

#[async_trait(?Send)]
impl Comms for CLIComms {
async fn get_signing_package(
&mut self,
Expand Down
2 changes: 2 additions & 0 deletions participant/src/comms/socket.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Socket implementation of the Comms trait, using message-io.

use async_trait::async_trait;
#[cfg(not(feature = "redpallas"))]
use frost_ed25519 as frost;
#[cfg(feature = "redpallas")]
Expand Down Expand Up @@ -74,6 +75,7 @@ impl SocketComms {
}
}

#[async_trait(?Send)]
impl Comms for SocketComms {
async fn get_signing_package(
&mut self,
Expand Down
2 changes: 1 addition & 1 deletion participant/src/round2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct Round2Config {
// TODO: refactor to generate config
// TODO: handle errors
pub async fn round_2_request_inputs(
comms: &mut impl Comms,
comms: &mut dyn Comms,
input: &mut impl BufRead,
logger: &mut dyn Write,
commitments: SigningCommitments,
Expand Down
Loading