Skip to content

Commit

Permalink
Fix Chain combinator
Browse files Browse the repository at this point in the history
  • Loading branch information
fjarri committed Nov 3, 2024
1 parent 0970081 commit 2d6d700
Show file tree
Hide file tree
Showing 14 changed files with 520 additions and 286 deletions.
10 changes: 6 additions & 4 deletions examples/src/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,16 @@ struct Round1Payload {
x: u8,
}

impl<Id: PartyId> FirstRound<Id> for Round1<Id> {
impl<Id: PartyId> EntryPoint<Id> for Round1<Id> {
type Inputs = Inputs<Id>;
type Protocol = SimpleProtocol;
const RESULT_ROUND: RoundId = RoundId::new(2);
fn new(
_rng: &mut impl CryptoRngCore,
_shared_randomness: &[u8],
id: Id,
inputs: Self::Inputs,
) -> Result<Self, LocalError> {
) -> Result<BoxedRound<Id, Self::Protocol>, LocalError> {
// Just some numbers associated with IDs to use in the dummy protocol.
// They will be the same on each node since IDs are ordered.
let ids_to_positions = inputs
Expand All @@ -169,13 +171,13 @@ impl<Id: PartyId> FirstRound<Id> for Round1<Id> {
let mut ids = inputs.all_ids;
ids.remove(&id);

Ok(Self {
Ok(BoxedRound::new_dynamic(Self {
context: Context {
id,
other_ids: ids,
ids_to_positions,
},
})
}))
}
}

Expand Down
5 changes: 1 addition & 4 deletions examples/src/simple_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::marker::PhantomData;

use manul::{combinators::*, protocol::PartyId};

use super::simple::{Inputs, Round1, SimpleProtocol};
use super::simple::{Inputs, Round1};

pub struct ChainedSimple<Id>(PhantomData<Id>);

Expand All @@ -23,9 +23,6 @@ impl<Id: PartyId> From<(NewInputs<Id>, u8)> for Inputs<Id> {
}

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>;
Expand Down
11 changes: 6 additions & 5 deletions examples/src/simple_malicious.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ use core::fmt::Debug;
use manul::{
combinators::{Misbehaving, MisbehavingInputs, MisbehavingRound},
protocol::{
Artifact, DirectMessage, LocalError, ObjectSafeRound, PartyId, ProtocolMessagePart, RoundId, Serializer,
Artifact, BoxedRound, Deserializer, DirectMessage, EntryPoint, LocalError, PartyId, ProtocolMessagePart,
RoundId, Serializer,
},
session::signature::Keypair,
testing::{run_sync, BinaryFormat, TestSessionParams, TestSigner, TestVerifier},
};
use rand_core::{CryptoRngCore, OsRng};
use tracing_subscriber::EnvFilter;

use crate::simple::{Inputs, Round1, Round1Message, Round2, Round2Message, SimpleProtocol};
use crate::simple::{Inputs, Round1, Round1Message, Round2, Round2Message};

#[derive(Debug, Clone, Copy)]
enum Behavior {
Expand All @@ -24,14 +25,14 @@ enum Behavior {
struct SimpleMaliciousProtocol;

impl<Id: PartyId> Misbehaving<Id, Behavior> for SimpleMaliciousProtocol {
type Protocol = SimpleProtocol;
type FirstRound = Round1<Id>;
type EntryPoint = Round1<Id>;

fn amend_direct_message(
_rng: &mut impl CryptoRngCore,
round: &dyn ObjectSafeRound<Id, Protocol = Self::Protocol>,
round: &BoxedRound<Id, <Self::EntryPoint as EntryPoint<Id>>::Protocol>,
behavior: &Behavior,
serializer: &Serializer,
_deserializer: &Deserializer,
_destination: &Id,
direct_message: DirectMessage,
artifact: Option<Artifact>,
Expand Down
4 changes: 2 additions & 2 deletions manul/benches/empty_rounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use core::fmt::Debug;
use criterion::{criterion_group, criterion_main, Criterion};
use manul::{
protocol::{
Artifact, Deserializer, DirectMessage, EchoBroadcast, FinalizeError, FinalizeOutcome, FirstRound, LocalError,
Artifact, Deserializer, DirectMessage, EchoBroadcast, EntryPoint, FinalizeError, FinalizeOutcome, LocalError,
NormalBroadcast, PartyId, Payload, Protocol, ProtocolError, ProtocolMessagePart, ProtocolValidationError,
ReceiveError, Round, RoundId, Serializer,
},
Expand Down Expand Up @@ -73,7 +73,7 @@ struct Round1Payload;

struct Round1Artifact;

impl<Id: PartyId> FirstRound<Id> for EmptyRound<Id> {
impl<Id: PartyId> EntryPoint<Id> for EmptyRound<Id> {
type Inputs = Inputs<Id>;
fn new(
_rng: &mut impl CryptoRngCore,
Expand Down
Loading

0 comments on commit 2d6d700

Please sign in to comment.