-
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.
WIP started work on recursive executor
- Loading branch information
1 parent
2166cfa
commit 419e45f
Showing
6 changed files
with
197 additions
and
23 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
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use crate::circuit::sub_circuit::{SubCircIter, SubCircLayer}; | ||
use crate::circuit::{base_circuit, GateIdx}; | ||
use crate::executor::DynFDSetup; | ||
use crate::protocols::{Protocol, ShareStorage}; | ||
use crate::sub_circ_executor::storage::Storage; | ||
use std::mem; | ||
use std::ops::Range; | ||
|
||
pub enum LayerExecutor<P: Protocol, Idx: GateIdx> { | ||
ConstructMsg { | ||
base_layer: base_circuit::CircuitLayer<P::Gate, Idx>, | ||
sub_executors: Vec<Self>, | ||
}, | ||
ProcessMsg { | ||
base_layer: base_circuit::CircuitLayer<P::Gate, Idx>, | ||
setup: P::SetupStorage, | ||
sub_executors: Vec<Self>, | ||
msg_range: Range<usize>, | ||
}, | ||
} | ||
|
||
impl<P: Protocol, Idx: GateIdx> LayerExecutor<P, Idx> { | ||
async fn construct_msg( | ||
&mut self, | ||
layer: &mut SubCircLayer<'_, '_, P::Gate, Idx>, | ||
storage: &mut Storage<P::ShareStorage>, | ||
setup: &mut DynFDSetup<'_, P, Idx>, | ||
msg_buf: &mut (), | ||
) { | ||
match self { | ||
LayerExecutor::ConstructMsg { | ||
base_layer, | ||
sub_executors, | ||
} => { | ||
// handle the non-interactive part of base_layer | ||
// drop non-interactive part | ||
let setup_data = setup.request_setup_output(42).await.unwrap(); | ||
// handle interactive part, write msg to msg_buf -> record msg offset | ||
// change self type to process_msg | ||
|
||
for mut sub_layer in layer.sub_layer_iter() { | ||
let mut sub_executor = LayerExecutor::ConstructMsg { | ||
base_layer: mem::take(&mut sub_layer.base_layer), | ||
sub_executors: vec![], | ||
}; | ||
let sub_storage = storage.sub_storage_mut(sub_layer.call_id); | ||
sub_executor | ||
.construct_msg(&mut sub_layer, sub_storage, setup, msg_buf) | ||
.await; | ||
sub_executors.push(sub_executor); | ||
} | ||
} | ||
LayerExecutor::ProcessMsg { .. } => { | ||
unreachable!() | ||
} | ||
} | ||
|
||
todo!() | ||
} | ||
|
||
fn process_msg( | ||
&mut self, | ||
storage: &mut Storage<P::ShareStorage>, | ||
own_msg_buf: &mut (), | ||
other_msg_buf: &mut (), | ||
) { | ||
todo!() | ||
} | ||
} | ||
|
||
// impl LayerExecutor { | ||
// fn handle_before() { | ||
// handle_non_interactive(layer) | ||
// let msg_idx = handle_interactive(layer, &mut msg_buf) | ||
// for sub_layer in layer: | ||
// sub_executor = LayerExecutor::BeforeInteractive { layer: sub_layer, ... } | ||
// sub_executor.handle_before() | ||
// self.sub_executors.push(sub_executor) | ||
// } |
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,59 @@ | ||
use crate::circuit::sub_circuit::SubCircIter; | ||
use crate::circuit::{sub_circuit, GateIdx}; | ||
use crate::errors::ExecutorError; | ||
use crate::executor::DynFDSetup; | ||
use crate::protocols::Protocol; | ||
use crate::sub_circ_executor::storage::{ScalarOrSimd, Storage}; | ||
use seec_channel::{Receiver, Sender}; | ||
use serde::{Deserialize, Serialize}; | ||
use std::fmt::{Display, Formatter}; | ||
|
||
mod layer_executor; | ||
mod storage; | ||
|
||
pub struct PartyId(pub usize); | ||
|
||
pub struct Executor<'c, P: Protocol, Idx> { | ||
circuit: &'c sub_circuit::Circuit<P::Gate, Idx>, | ||
setup: DynFDSetup<'c, P, Idx>, | ||
layer_executor: LayerExecutor<P>, | ||
} | ||
|
||
struct LayerExecutor<P: Protocol> { | ||
protocol_state: P, | ||
storage: Storage<P::ShareStorage>, | ||
party_id: PartyId, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, Default)] | ||
pub struct ExecutorMsg<Msg, SimdMsg> { | ||
scalar: Msg, | ||
simd: Option<SimdMsg>, | ||
} | ||
|
||
pub type Message<P> = ExecutorMsg<<P as Protocol>::Msg, <P as Protocol>::SimdMsg>; | ||
|
||
impl<'c, P: Protocol, Idx: GateIdx> Executor<'c, P, Idx> { | ||
#[tracing::instrument(skip_all, fields(party_id = %self.layer_executor.party_id), err)] | ||
pub async fn execute( | ||
&mut self, | ||
inputs: ScalarOrSimd<P::ShareStorage>, | ||
sender: &mut Sender<Message<P>>, | ||
receiver: &mut Receiver<Message<P>>, | ||
) -> Result<ScalarOrSimd<P::ShareStorage>, ExecutorError> { | ||
let mut main_iter = SubCircIter::new_main(&self.circuit); | ||
|
||
while let Some(layer) = main_iter.next() {} | ||
todo!() | ||
} | ||
} | ||
|
||
impl<P: Protocol> LayerExecutor<P> { | ||
fn handle_layer(&mut self) {} | ||
} | ||
|
||
impl Display for PartyId { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
self.0.fmt(f) | ||
} | ||
} |
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,25 @@ | ||
use crate::circuit::sub_circuit::CallId; | ||
use crate::circuit::GateIdx; | ||
use crate::GateId; | ||
use serde::{Deserialize, Serialize}; | ||
use std::ops::Index; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub enum ScalarOrSimd<Shares> { | ||
Scalar(Shares), | ||
Simd(Vec<Shares>), | ||
} | ||
|
||
pub struct Storage<Shares> { | ||
own: ScalarOrSimd<Shares>, | ||
sub_circuit: Vec<Storage<Shares>>, | ||
} | ||
|
||
impl<Shares> Storage<Shares> { | ||
pub(crate) fn sub_storage_mut(&mut self, call_id: CallId) -> &mut Self { | ||
let CallId::Call(id) = call_id else { | ||
panic!("Can't index storage with CallId::Ret") | ||
}; | ||
&mut self.sub_circuit[id as usize] | ||
} | ||
} |