-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
435 additions
and
0 deletions.
There are no files selected for viewing
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,7 @@ | ||
extern crate alloc; | ||
|
||
pub mod simple; | ||
mod simple_chain; | ||
|
||
#[cfg(test)] | ||
mod simple_malicious; |
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,86 @@ | ||
use core::fmt::Debug; | ||
use core::marker::PhantomData; | ||
|
||
use manul::{combinators::*, protocol::PartyId}; | ||
|
||
use super::simple::{Inputs, Round1, SimpleProtocol}; | ||
|
||
pub struct ChainedSimple<Id>(PhantomData<Id>); | ||
|
||
#[derive(Debug)] | ||
pub struct NewInputs<Id>(Inputs<Id>); | ||
|
||
impl<'a, Id: PartyId> From<&'a NewInputs<Id>> for Inputs<Id> { | ||
fn from(source: &'a NewInputs<Id>) -> Self { | ||
source.0.clone() | ||
} | ||
} | ||
|
||
impl<Id: PartyId> From<(NewInputs<Id>, u8)> for Inputs<Id> { | ||
fn from(source: (NewInputs<Id>, u8)) -> Self { | ||
source.0 .0 | ||
} | ||
} | ||
|
||
impl<Id: PartyId> Chained<Id> for ChainedSimple<Id> { | ||
type Protocol1 = SimpleProtocol; | ||
type Protocol2 = SimpleProtocol; | ||
type CorrectnessProof = (); | ||
type Inputs = NewInputs<Id>; | ||
type EntryPoint1 = Round1<Id>; | ||
type EntryPoint2 = Round1<Id>; | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use alloc::collections::BTreeSet; | ||
|
||
use manul::{ | ||
combinators::Chain, | ||
session::{signature::Keypair, SessionOutcome}, | ||
testing::{run_sync, BinaryFormat, TestSessionParams, TestSigner, TestVerifier}, | ||
}; | ||
use rand_core::OsRng; | ||
use tracing_subscriber::EnvFilter; | ||
|
||
use super::{ChainedSimple, NewInputs}; | ||
use crate::simple::Inputs; | ||
|
||
#[test] | ||
fn round() { | ||
let signers = (0..3).map(TestSigner::new).collect::<Vec<_>>(); | ||
let all_ids = signers | ||
.iter() | ||
.map(|signer| signer.verifying_key()) | ||
.collect::<BTreeSet<_>>(); | ||
let inputs = signers | ||
.into_iter() | ||
.map(|signer| { | ||
( | ||
signer, | ||
NewInputs(Inputs { | ||
all_ids: all_ids.clone(), | ||
}), | ||
) | ||
}) | ||
.collect::<Vec<_>>(); | ||
|
||
let my_subscriber = tracing_subscriber::fmt() | ||
.with_env_filter(EnvFilter::from_default_env()) | ||
.finish(); | ||
let reports = tracing::subscriber::with_default(my_subscriber, || { | ||
run_sync::<Chain<TestVerifier, ChainedSimple<TestVerifier>>, TestSessionParams<BinaryFormat>>( | ||
&mut OsRng, inputs, | ||
) | ||
.unwrap() | ||
}); | ||
|
||
for (_id, report) in reports { | ||
if let SessionOutcome::Result(result) = report.outcome { | ||
assert_eq!(result, 3); // 0 + 1 + 2 | ||
} else { | ||
panic!("Session did not finish successfully"); | ||
} | ||
} | ||
} | ||
} |
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,3 +1,5 @@ | ||
mod chain; | ||
mod misbehave; | ||
|
||
pub use chain::{Chain, Chained, ChainedProtocol}; | ||
pub use misbehave::{Misbehaving, MisbehavingInputs, MisbehavingRound}; |
Oops, something went wrong.