-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve consistency of testing across projects (#76)
* Update participant tests to use DKG format (#37) Update Makefile to not run --all-features in tests cli tests were not touched * Update tests in trusted dealer (#37) * Refactor test files structure to be consistent across projects (#37) * Add cross project integration test (#37) * Remove empty test files (#37) * Remove reference to old test (#37) * print entire identifier instead of converting back to integer * Remove commented code (#37) * Add signature verification step to participant demo (#78) * Add verification step to participant demo (#56) * Add cli test to participant (#56) Clean up some comments and prints --------- Co-authored-by: Conrado Gouvea <[email protected]>
- Loading branch information
1 parent
c6056d0
commit 0c52892
Showing
36 changed files
with
652 additions
and
716 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
pub mod cli; | ||
|
||
mod step_1; | ||
mod step_2; | ||
mod step_3; | ||
|
||
#[cfg(test)] | ||
mod tests; | ||
pub mod step_1; | ||
pub mod step_2; | ||
pub mod step_3; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod cli; | ||
pub mod inputs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
mod inputs_tests; | ||
mod integration_test; | ||
mod inputs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#[cfg(test)] | ||
mod integration_tests; |
4 changes: 2 additions & 2 deletions
4
dkg/src/tests/integration_test.rs → dkg/tests/integration_tests.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,63 @@ | ||
use frost::{Error, Signature}; | ||
#[cfg(not(feature = "redpallas"))] | ||
use frost_ed25519 as frost; | ||
#[cfg(feature = "redpallas")] | ||
use reddsa::frost::redpallas as frost; | ||
|
||
use frost::{round1, Error}; | ||
use participant::round1::{print_values, request_inputs}; | ||
use participant::round2::{generate_signature, print_values_round_2, round_2_request_inputs}; | ||
use participant::Logger; | ||
use crate::round1::{print_values, request_inputs}; | ||
use crate::round2::{generate_signature, print_values_round_2, round_2_request_inputs}; | ||
use rand::thread_rng; | ||
use std::io::BufRead; | ||
use std::io::{BufRead, Write}; | ||
|
||
#[derive(PartialEq)] | ||
pub enum CliError { | ||
Config, | ||
Signing, | ||
} | ||
pub fn cli( | ||
input: &mut impl BufRead, | ||
logger: &mut impl Write, | ||
) -> Result<(), Box<dyn std::error::Error>> { | ||
let round_1_config = request_inputs(input, logger)?; | ||
|
||
pub struct ParticipantError { | ||
pub frost_error: Error, | ||
pub cli_error: CliError, | ||
} | ||
let key_package = round_1_config.key_package; | ||
|
||
// This is a little messy because of the use of unwrap(). This can be improved. | ||
pub fn cli(input: &mut impl BufRead, logger: &mut dyn Logger) -> Result<(), ParticipantError> { | ||
let round_1_config = request_inputs(input, logger); | ||
writeln!(logger, "Key Package succesfully created.")?; | ||
|
||
if let Err(e) = round_1_config { | ||
return Err(ParticipantError { | ||
frost_error: e, | ||
cli_error: CliError::Config, | ||
}); | ||
} | ||
let mut rng = thread_rng(); | ||
let (nonces, commitments) = frost::round1::commit(key_package.secret_share(), &mut rng); | ||
|
||
let round_1_config_ok = round_1_config.unwrap(); | ||
print_values(commitments, logger)?; | ||
|
||
let key_package_ok = round_1_config_ok.key_package; | ||
let round_2_config = round_2_request_inputs(input, logger)?; | ||
|
||
logger.log("Key Package succesfully created.".to_string()); | ||
let config_message = round_2_config.clone(); | ||
|
||
let mut rng = thread_rng(); | ||
let (nonces, commitments) = round1::commit(key_package_ok.secret_share(), &mut rng); | ||
// Sign | ||
|
||
print_values(commitments, logger); | ||
let signature = generate_signature(round_2_config, &key_package, &nonces)?; | ||
|
||
let round_2_config = round_2_request_inputs(input, logger); // TODO: handle errors | ||
print_values_round_2(signature, logger)?; | ||
|
||
if let Err(e) = round_2_config { | ||
return Err(ParticipantError { | ||
frost_error: e, | ||
cli_error: CliError::Config, | ||
}); | ||
} | ||
let group_signature = request_signature(input, logger)?; | ||
key_package | ||
.group_public() | ||
.verify(config_message.signing_package.message(), &group_signature)?; | ||
|
||
let round_2_config_ok = round_2_config.unwrap(); | ||
writeln!(logger, "Group Signature verified.")?; | ||
|
||
// Sign | ||
Ok(()) | ||
} | ||
|
||
let signature = generate_signature(round_2_config_ok, &key_package_ok, &nonces); // TODO: handle errors | ||
fn request_signature( | ||
input: &mut impl BufRead, | ||
logger: &mut impl Write, | ||
) -> Result<Signature, Box<dyn std::error::Error>> { | ||
writeln!(logger, "The group signature:")?; | ||
|
||
if let Err(e) = signature { | ||
return Err(ParticipantError { | ||
frost_error: e, | ||
cli_error: CliError::Signing, | ||
}); | ||
} | ||
let mut signature_input = String::new(); | ||
|
||
print_values_round_2(signature.unwrap(), logger); | ||
input.read_line(&mut signature_input)?; | ||
|
||
Ok(()) | ||
let group_signature = | ||
serde_json::from_str(signature_input.trim()).map_err(|_| Error::InvalidSignature)?; | ||
|
||
// TODO: add redpallas feature | ||
|
||
Ok(group_signature) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
pub mod cli; | ||
pub mod round1; | ||
pub mod round2; | ||
|
||
pub trait Logger { | ||
fn log(&mut self, value: String); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,19 @@ | ||
mod cli; | ||
mod round1; | ||
mod round2; | ||
|
||
#[cfg(test)] | ||
mod tests; | ||
|
||
use cli::{cli, CliError}; | ||
use participant::Logger; | ||
use cli::cli; | ||
|
||
use std::io; | ||
|
||
fn main() -> io::Result<()> { | ||
// TODO: Update to use exit codes | ||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let mut reader = Box::new(io::stdin().lock()); | ||
let mut logger = ConsoleLogger; | ||
let out = cli(&mut reader, &mut logger); | ||
|
||
if let Err(e) = out { | ||
if e.cli_error == CliError::Config { | ||
{ | ||
eprintln!("Error: {}", e.frost_error); | ||
std::process::exit(exitcode::DATAERR) | ||
}; | ||
}; | ||
if e.cli_error == CliError::Signing { | ||
eprintln!("Error: {}", e.frost_error); | ||
std::process::exit(1) | ||
}; | ||
} | ||
let mut logger = io::stdout(); | ||
cli(&mut reader, &mut logger)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct ConsoleLogger; | ||
|
||
impl Logger for ConsoleLogger { | ||
fn log(&mut self, value: String) { | ||
println!("{}", value); | ||
} | ||
} |
Oops, something went wrong.