diff --git a/packages/ciphernode/core/src/ciphernode.rs b/packages/ciphernode/core/src/ciphernode.rs index 78e6bc98..4c09fb22 100644 --- a/packages/ciphernode/core/src/ciphernode.rs +++ b/packages/ciphernode/core/src/ciphernode.rs @@ -1,9 +1,9 @@ use crate::{ data::{Data, Insert}, eventbus::EventBus, - events::{ComputationRequested, EnclaveEvent, KeyshareCreated}, + events::{CommitteeRequested, EnclaveEvent, KeyshareCreated}, fhe::{Fhe, GenerateKeyshare}, - DecryptCiphertext, DecryptionRequested, DecryptionshareCreated, Get, Subscribe, + CiphertextOutputPublished, DecryptCiphertext, DecryptionshareCreated, Get, Subscribe, }; use actix::prelude::*; use anyhow::Result; @@ -26,10 +26,13 @@ impl Ciphernode { pub async fn attach(bus: Addr, fhe: Addr, data: Addr) -> Addr { let node = Ciphernode::new(bus.clone(), fhe, data).start(); let _ = bus - .send(Subscribe::new("ComputationRequested", node.clone().into())) + .send(Subscribe::new("CommitteeRequested", node.clone().into())) .await; let _ = bus - .send(Subscribe::new("DecryptionRequested", node.clone().into())) + .send(Subscribe::new( + "CiphertextOutputPublished", + node.clone().into(), + )) .await; node } @@ -40,32 +43,28 @@ impl Handler for Ciphernode { fn handle(&mut self, event: EnclaveEvent, ctx: &mut Context) -> Self::Result { match event { - EnclaveEvent::ComputationRequested { data, .. } => ctx.address().do_send(data), - EnclaveEvent::DecryptionRequested { data, .. } => ctx.address().do_send(data), + EnclaveEvent::CommitteeRequested { data, .. } => ctx.address().do_send(data), + EnclaveEvent::CiphertextOutputPublished { data, .. } => ctx.address().do_send(data), _ => (), } } } -impl Handler for Ciphernode { +impl Handler for Ciphernode { type Result = ResponseFuture<()>; - fn handle(&mut self, event: ComputationRequested, _: &mut Context) -> Self::Result { + fn handle(&mut self, event: CommitteeRequested, _: &mut Context) -> Self::Result { let fhe = self.fhe.clone(); let data = self.data.clone(); let bus = self.bus.clone(); - Box::pin(async { - on_computation_requested(fhe, data, bus, event) - .await - .unwrap() - }) + Box::pin(async { on_committee_requested(fhe, data, bus, event).await.unwrap() }) } } -impl Handler for Ciphernode { +impl Handler for Ciphernode { type Result = ResponseFuture<()>; - fn handle(&mut self, event: DecryptionRequested, _: &mut Context) -> Self::Result { + fn handle(&mut self, event: CiphertextOutputPublished, _: &mut Context) -> Self::Result { let fhe = self.fhe.clone(); let data = self.data.clone(); let bus = self.bus.clone(); @@ -77,13 +76,13 @@ impl Handler for Ciphernode { } } -async fn on_computation_requested( +async fn on_committee_requested( fhe: Addr, data: Addr, bus: Addr, - event: ComputationRequested, + event: CommitteeRequested, ) -> Result<()> { - let ComputationRequested { e3_id, .. } = event; + let CommitteeRequested { e3_id, .. } = event; // generate keyshare let (sk, pubkey) = fhe.send(GenerateKeyshare {}).await??; @@ -108,9 +107,12 @@ async fn on_decryption_requested( fhe: Addr, data: Addr, bus: Addr, - event: DecryptionRequested, + event: CiphertextOutputPublished, ) -> Result<()> { - let DecryptionRequested { e3_id, ciphertext } = event; + let CiphertextOutputPublished { + e3_id, + ciphertext_output, + } = event; // get secret key by id from data let Some(unsafe_secret) = data.send(Get(format!("{}/sk", e3_id).into())).await? else { @@ -119,7 +121,7 @@ async fn on_decryption_requested( let decryption_share = fhe .send(DecryptCiphertext { - ciphertext, + ciphertext: ciphertext_output, unsafe_secret, }) .await??; diff --git a/packages/ciphernode/core/src/committee.rs b/packages/ciphernode/core/src/committee.rs index 507cb7bb..807402ba 100644 --- a/packages/ciphernode/core/src/committee.rs +++ b/packages/ciphernode/core/src/committee.rs @@ -45,11 +45,11 @@ impl CommitteeManager { pub fn attach(bus: Addr, fhe: Addr) -> Addr { let addr = CommitteeManager::new(bus.clone(), fhe).start(); bus.do_send(Subscribe::new( - "ComputationRequested", + "CommitteeRequested", addr.clone().recipient(), )); bus.do_send(Subscribe::new("KeyshareCreated", addr.clone().into())); - bus.do_send(Subscribe::new("DecryptionRequested", addr.clone().into())); + bus.do_send(Subscribe::new("CiphertextOutputPublished", addr.clone().into())); bus.do_send(Subscribe::new("DecryptionshareCreated", addr.clone().into())); bus.do_send(Subscribe::new("DecryptionOutputPublished", addr.clone().into())); addr @@ -61,7 +61,7 @@ impl Handler for CommitteeManager { fn handle(&mut self, event: EnclaveEvent, _ctx: &mut Self::Context) -> Self::Result { match event { - EnclaveEvent::ComputationRequested { data, .. } => { + EnclaveEvent::CommitteeRequested { data, .. } => { // start up a new key let key = CommitteeKey::new( self.fhe.clone(), @@ -92,7 +92,7 @@ impl Handler for CommitteeManager { key.do_send(Die); self.keys.remove(&data.e3_id); } - EnclaveEvent::DecryptionRequested { data, .. } => { + EnclaveEvent::CiphertextOutputPublished { data, .. } => { let Some(meta) = self.meta.get(&data.e3_id) else { // TODO: setup proper logger / telemetry println!("E3Id not found in committee"); diff --git a/packages/ciphernode/core/src/events.rs b/packages/ciphernode/core/src/events.rs index 600cd926..d1949a37 100644 --- a/packages/ciphernode/core/src/events.rs +++ b/packages/ciphernode/core/src/events.rs @@ -55,17 +55,17 @@ pub enum EnclaveEvent { id: EventId, data: KeyshareCreated, }, - ComputationRequested { + CommitteeRequested { id: EventId, - data: ComputationRequested, + data: CommitteeRequested, }, PublicKeyAggregated { id: EventId, data: PublicKeyAggregated, }, - DecryptionRequested { + CiphertextOutputPublished { id: EventId, - data: DecryptionRequested, + data: CiphertextOutputPublished, }, DecryptionshareCreated { id: EventId, @@ -100,9 +100,9 @@ impl From for EventId { fn from(value: EnclaveEvent) -> Self { match value { EnclaveEvent::KeyshareCreated { id, .. } => id, - EnclaveEvent::ComputationRequested { id, .. } => id, + EnclaveEvent::CommitteeRequested { id, .. } => id, EnclaveEvent::PublicKeyAggregated { id, .. } => id, - EnclaveEvent::DecryptionRequested { id, .. } => id, + EnclaveEvent::CiphertextOutputPublished { id, .. } => id, EnclaveEvent::DecryptionshareCreated { id, .. } => id, EnclaveEvent::DecryptedOutputPublished { id, .. } => id, } @@ -118,9 +118,9 @@ impl From for EnclaveEvent { } } -impl From for EnclaveEvent { - fn from(data: ComputationRequested) -> Self { - EnclaveEvent::ComputationRequested { +impl From for EnclaveEvent { + fn from(data: CommitteeRequested) -> Self { + EnclaveEvent::CommitteeRequested { id: EventId::from(data.clone()), data: data.clone(), } @@ -136,9 +136,9 @@ impl From for EnclaveEvent { } } -impl From for EnclaveEvent { - fn from(data: DecryptionRequested) -> Self { - EnclaveEvent::DecryptionRequested { +impl From for EnclaveEvent { + fn from(data: CiphertextOutputPublished) -> Self { + EnclaveEvent::CiphertextOutputPublished { id: EventId::from(data.clone()), data: data.clone(), } @@ -191,7 +191,7 @@ pub struct PublicKeyAggregated { #[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] #[rtype(result = "()")] -pub struct ComputationRequested { +pub struct CommitteeRequested { pub e3_id: E3id, pub nodecount: usize, pub threshold: usize, @@ -204,9 +204,9 @@ pub struct ComputationRequested { #[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] #[rtype(result = "()")] -pub struct DecryptionRequested { +pub struct CiphertextOutputPublished { pub e3_id: E3id, - pub ciphertext: Vec + pub ciphertext_output: Vec } #[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] diff --git a/packages/ciphernode/core/src/lib.rs b/packages/ciphernode/core/src/lib.rs index 1fe52611..b24c285d 100644 --- a/packages/ciphernode/core/src/lib.rs +++ b/packages/ciphernode/core/src/lib.rs @@ -63,14 +63,14 @@ mod tests { committee::CommitteeManager, data::Data, eventbus::{EventBus, GetHistory}, - events::{ComputationRequested, E3id, EnclaveEvent, KeyshareCreated, PublicKeyAggregated}, + events::{CommitteeRequested, E3id, EnclaveEvent, KeyshareCreated, PublicKeyAggregated}, fhe::Fhe, p2p::P2p, serializers::{ CiphertextSerializer, DecryptionShareSerializer, PublicKeySerializer, PublicKeyShareSerializer, }, - DecryptedOutputPublished, DecryptionRequested, DecryptionshareCreated, ResetHistory, + DecryptedOutputPublished, CiphertextOutputPublished, DecryptionshareCreated, ResetHistory, }; use actix::prelude::*; use anyhow::*; @@ -166,7 +166,7 @@ mod tests { let e3_id = E3id::new("1234"); - let event = EnclaveEvent::from(ComputationRequested { + let event = EnclaveEvent::from(CommitteeRequested { e3_id: e3_id.clone(), nodecount: 3, threshold: 123, @@ -203,7 +203,7 @@ mod tests { assert_eq!( history, vec![ - EnclaveEvent::from(ComputationRequested { + EnclaveEvent::from(CommitteeRequested { e3_id: e3_id.clone(), nodecount: 3, threshold: 123, @@ -243,8 +243,8 @@ mod tests { let ciphertext = pubkey.try_encrypt(&pt, &mut ChaCha20Rng::seed_from_u64(42))?; - let event = EnclaveEvent::from(DecryptionRequested { - ciphertext: CiphertextSerializer::to_bytes(ciphertext.clone(), params.clone())?, + let event = EnclaveEvent::from(CiphertextOutputPublished { + ciphertext_output: CiphertextSerializer::to_bytes(ciphertext.clone(), params.clone())?, e3_id: e3_id.clone(), }); @@ -316,14 +316,14 @@ mod tests { } }); - let evt_1 = EnclaveEvent::from(ComputationRequested { + let evt_1 = EnclaveEvent::from(CommitteeRequested { e3_id: E3id::new("1234"), nodecount: 3, threshold: 123, sortition_seed: 123, }); - let evt_2 = EnclaveEvent::from(ComputationRequested { + let evt_2 = EnclaveEvent::from(CommitteeRequested { e3_id: E3id::new("1235"), nodecount: 3, threshold: 123, @@ -362,7 +362,7 @@ mod tests { P2p::spawn_and_listen(bus.clone(), tx.clone(), rx); // Capture messages from output on msgs vec - let event = EnclaveEvent::from(ComputationRequested { + let event = EnclaveEvent::from(CommitteeRequested { e3_id: E3id::new("1235"), nodecount: 3, threshold: 123, diff --git a/packages/ciphernode/enclave_node/src/bin/cmd.rs b/packages/ciphernode/enclave_node/src/bin/cmd.rs index 4ac97462..9984408f 100644 --- a/packages/ciphernode/enclave_node/src/bin/cmd.rs +++ b/packages/ciphernode/enclave_node/src/bin/cmd.rs @@ -1,7 +1,7 @@ use std::error::Error; use enclave_core::Actor; -use enclave_core::ComputationRequested; +use enclave_core::CommitteeRequested; use enclave_core::E3id; use enclave_core::EnclaveEvent; use enclave_core::EventBus; @@ -22,7 +22,7 @@ async fn main() -> Result<(), Box> { match line.as_str() { "test" => { id += 1; - bus.do_send(EnclaveEvent::from(ComputationRequested { + bus.do_send(EnclaveEvent::from(CommitteeRequested { e3_id: E3id::from(id), nodecount: 3, threshold: 3,