Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jobs:
run: pnpm rust:lint

- name: Run Integration Tests
run: 'cargo test --test integration -- --nocapture && cargo test --test integration_legacy -- --nocapture'
run: 'cargo test --test integration -- --nocapture'

build_e3_support_risc0:
runs-on: ubuntu-latest
Expand Down
129 changes: 3 additions & 126 deletions crates/aggregator/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ use std::sync::Arc;

use crate::keyshare_created_filter_buffer::KeyshareCreatedFilterBuffer;
use crate::{
PlaintextAggregator, PlaintextAggregatorParams, PlaintextAggregatorState,
PlaintextRepositoryFactory, PublicKeyAggregator, PublicKeyAggregatorParams,
PublicKeyAggregatorState, PublicKeyRepositoryFactory, ThresholdPlaintextAggregator,
ThresholdPlaintextAggregatorParams, ThresholdPlaintextAggregatorState,
TrBfvPlaintextRepositoryFactory,
PublicKeyAggregator, PublicKeyAggregatorParams, PublicKeyAggregatorState,
PublicKeyRepositoryFactory, ThresholdPlaintextAggregator, ThresholdPlaintextAggregatorParams,
ThresholdPlaintextAggregatorState, TrBfvPlaintextRepositoryFactory,
};
use actix::{Actor, Addr, Recipient};
use anyhow::{anyhow, Result};
Expand All @@ -25,127 +23,6 @@ use e3_fhe::Fhe;
use e3_request::{E3Context, E3ContextSnapshot, E3Extension, META_KEY};
use e3_sortition::Sortition;

#[deprecated = "In favour of ThresholdPlaintextAggregatorExtension"]
pub struct PlaintextAggregatorExtension {
bus: BusHandle,
sortition: Addr<Sortition>,
}

impl PlaintextAggregatorExtension {
pub fn create(bus: &BusHandle, sortition: &Addr<Sortition>) -> Box<Self> {
Box::new(Self {
bus: bus.clone(),
sortition: sortition.clone(),
})
}
}

const ERROR_PLAINTEXT_FHE_MISSING:&str = "Could not create PlaintextAggregator because the fhe instance it depends on was not set on the context.";
const ERROR_PLAINTEXT_META_MISSING:&str = "Could not create PlaintextAggregator because the meta instance it depends on was not set on the context.";

#[async_trait]
impl E3Extension for PlaintextAggregatorExtension {
fn on_event(&self, ctx: &mut E3Context, evt: &EnclaveEvent) {
// Save plaintext aggregator
let EnclaveEventData::CiphertextOutputPublished(data) = evt.get_data() else {
return;
};

let Some(fhe) = ctx.get_dependency(FHE_KEY) else {
self.bus.err(
EType::PlaintextAggregation,
anyhow!(ERROR_PLAINTEXT_FHE_MISSING),
);
return;
};

let Some(ref meta) = ctx.get_dependency(META_KEY) else {
self.bus.err(
EType::PlaintextAggregation,
anyhow!(ERROR_PLAINTEXT_META_MISSING),
);
return;
};

let e3_id = data.e3_id.clone();
let repo = ctx.repositories().plaintext(&e3_id);

// This is a single ciphertext for the legacy PlaintextAggregator
let Some(single_ciphertext) = data.ciphertext_output.first() else {
self.bus.err(
EType::PlaintextAggregation,
anyhow!("Could not extract ciphertext from array"),
);
return;
};

let sync_state = repo.send(Some(PlaintextAggregatorState::init(
meta.threshold_m,
meta.threshold_n,
meta.seed,
single_ciphertext.clone(),
)));

ctx.set_event_recipient(
"plaintext",
Some(
PlaintextAggregator::new(
PlaintextAggregatorParams {
fhe: fhe.clone(),
bus: self.bus.clone(),
sortition: self.sortition.clone(),
e3_id: e3_id.clone(),
},
sync_state,
)
.start()
.into(),
),
);
}

async fn hydrate(&self, ctx: &mut E3Context, snapshot: &E3ContextSnapshot) -> Result<()> {
// No ID on the snapshot -> bail
if !snapshot.contains("plaintext") {
return Ok(());
}

let repo = ctx.repositories().plaintext(&snapshot.e3_id);
let sync_state = repo.load().await?;

// No Snapshot returned from the store -> bail
if !sync_state.has() {
return Ok(());
};

// Get deps
let Some(fhe) = ctx.get_dependency(FHE_KEY) else {
self.bus.err(
EType::PlaintextAggregation,
anyhow!(ERROR_PLAINTEXT_FHE_MISSING),
);
return Ok(());
};

let value = PlaintextAggregator::new(
PlaintextAggregatorParams {
fhe: fhe.clone(),
bus: self.bus.clone(),
sortition: self.sortition.clone(),
e3_id: ctx.e3_id.clone(),
},
sync_state,
)
.start()
.into();

// send to context
ctx.set_event_recipient("plaintext", Some(value));

Ok(())
}
}

pub struct PublicKeyAggregatorExtension {
bus: BusHandle,
}
Expand Down
4 changes: 0 additions & 4 deletions crates/aggregator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@
mod committee_finalizer;
pub mod ext;
mod keyshare_created_filter_buffer;
mod plaintext_aggregator;
mod publickey_aggregator;
mod repo;
mod threshold_plaintext_aggregator;
pub use committee_finalizer::CommitteeFinalizer;
pub use plaintext_aggregator::{
PlaintextAggregator, PlaintextAggregatorParams, PlaintextAggregatorState,
};
pub use publickey_aggregator::{
PublicKeyAggregator, PublicKeyAggregatorParams, PublicKeyAggregatorState,
};
Expand Down
Loading
Loading