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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 24 additions & 17 deletions crates/aggregator/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,11 @@ use e3_sortition::Sortition;

pub struct PublicKeyAggregatorExtension {
bus: BusHandle,
params_preset: BfvPreset,
}

impl PublicKeyAggregatorExtension {
pub fn create(bus: &BusHandle, params_preset: BfvPreset) -> Box<Self> {
Box::new(Self {
bus: bus.clone(),
params_preset,
})
pub fn create(bus: &BusHandle) -> Box<Self> {
Box::new(Self { bus: bus.clone() })
}
}

Expand Down Expand Up @@ -66,6 +62,7 @@ impl E3Extension for PublicKeyAggregatorExtension {
threshold_n,
threshold_m,
seed,
params_preset,
..
} = data.clone();
let repo = ctx.repositories().publickey(&e3_id);
Expand All @@ -80,7 +77,7 @@ impl E3Extension for PublicKeyAggregatorExtension {
self.bus.clone(),
e3_id,
sync_state,
self.params_preset.clone(),
params_preset,
);

ctx.set_event_recipient("publickey", Some(value));
Expand Down Expand Up @@ -109,12 +106,20 @@ impl E3Extension for PublicKeyAggregatorExtension {

return Ok(());
};
let Some(meta) = ctx.get_dependency(META_KEY) else {
self.bus.err(
EType::PublickeyAggregation,
anyhow!(ERROR_PUBKEY_META_MISSING),
);

return Ok(());
};
let value = create_publickey_aggregator(
fhe.clone(),
self.bus.clone(),
ctx.e3_id.clone(),
sync_state,
self.params_preset.clone(),
meta.params_preset,
);

// send to context
Expand Down Expand Up @@ -151,19 +156,13 @@ fn create_publickey_aggregator(
pub struct ThresholdPlaintextAggregatorExtension {
bus: BusHandle,
sortition: Addr<Sortition>,
params_preset: BfvPreset,
}

impl ThresholdPlaintextAggregatorExtension {
pub fn create(
bus: &BusHandle,
sortition: &Addr<Sortition>,
params_preset: BfvPreset,
) -> Box<Self> {
pub fn create(bus: &BusHandle, sortition: &Addr<Sortition>) -> Box<Self> {
Box::new(Self {
bus: bus.clone(),
sortition: sortition.clone(),
params_preset,
})
}
}
Expand Down Expand Up @@ -213,7 +212,7 @@ impl E3Extension for ThresholdPlaintextAggregatorExtension {
bus: self.bus.clone(),
sortition: self.sortition.clone(),
e3_id: e3_id.clone(),
params_preset: self.params_preset.clone(),
params_preset: meta.params_preset,
},
sync_state,
)
Expand All @@ -239,12 +238,20 @@ impl E3Extension for ThresholdPlaintextAggregatorExtension {
return Ok(());
};

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

return Ok(());
};
let value = ThresholdPlaintextAggregator::new(
ThresholdPlaintextAggregatorParams {
bus: self.bus.clone(),
sortition: self.sortition.clone(),
e3_id: ctx.e3_id.clone(),
params_preset: self.params_preset.clone(),
params_preset: meta.params_preset,
},
sync_state,
)
Expand Down
21 changes: 2 additions & 19 deletions crates/ciphernode-builder/src/ciphernode_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use e3_evm::{
SlashingManagerSolWriter,
};
use e3_fhe::ext::FheExtension;
use e3_fhe_params::{BfvPreset, DEFAULT_BFV_PRESET};
use e3_keyshare::ext::ThresholdKeyshareExtension;
use e3_multithread::{Multithread, MultithreadReport, TaskPool};
use e3_net::{
Expand Down Expand Up @@ -466,11 +465,6 @@ impl CiphernodeBuilder {

if let Some(KeyshareKind::Threshold) = self.keyshare {
let _ = self.ensure_multithread(&bus);
// TODO: Make BfvPreset configurable via builder method (e.g., with_share_enc_preset())
// Currently hardcoded to InsecureDkg512 for DKG operations.
// Production deployments should use BfvPreset::SecureDkg8192.
let share_enc_preset = BfvPreset::InsecureDkg512;

let backend = self
.zk_backend
.as_ref()
Expand All @@ -486,7 +480,6 @@ impl CiphernodeBuilder {
&bus,
&self.cipher,
&addr,
share_enc_preset,
));

info!("Setting up ZK actors");
Expand All @@ -502,14 +495,7 @@ impl CiphernodeBuilder {
info!("Setting up PublicKeyAggregationExtension");
// Ensure multithread worker is available for C1 verification and C5 proof generation
let _ = self.ensure_multithread(&bus);
// TODO: Make BfvPreset configurable via builder method.
// Currently hardcoded to InsecureThreshold512 for C5 proof generation.
// Production deployments should use the appropriate threshold preset.
let aggregator_preset = DEFAULT_BFV_PRESET;
e3_builder = e3_builder.with(PublicKeyAggregatorExtension::create(
&bus,
aggregator_preset,
));
e3_builder = e3_builder.with(PublicKeyAggregatorExtension::create(&bus));

if self.keyshare.is_none() {
let backend = self
Expand All @@ -525,11 +511,8 @@ impl CiphernodeBuilder {
if self.threshold_plaintext_agg {
info!("Setting up ThresholdPlaintextAggregatorExtension");
let _ = self.ensure_multithread(&bus);
let aggregator_preset = DEFAULT_BFV_PRESET;
e3_builder = e3_builder.with(ThresholdPlaintextAggregatorExtension::create(
&bus,
&sortition,
aggregator_preset,
&bus, &sortition,
))
}

Expand Down
3 changes: 3 additions & 0 deletions crates/events/src/enclave_event/ciphernode_selected.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use crate::{E3id, Seed};
use actix::Message;
use e3_fhe_params::BfvPreset;
use e3_utils::utility_types::ArcBytes;
use serde::{Deserialize, Serialize};
use std::fmt::{self, Display};
Expand All @@ -19,6 +20,7 @@ pub struct CiphernodeSelected {
pub seed: Seed,
pub error_size: ArcBytes,
pub esi_per_ct: usize,
pub params_preset: BfvPreset,
pub params: ArcBytes,
pub party_id: u64,
}
Expand All @@ -29,6 +31,7 @@ impl Default for CiphernodeSelected {
e3_id: E3id::new("0", 0),
error_size: ArcBytes::from_bytes(&[]),
esi_per_ct: 0,
params_preset: BfvPreset::InsecureThreshold512,
params: ArcBytes::from_bytes(&[]),
party_id: 0,
seed: Seed([0u8; 32]),
Expand Down
8 changes: 7 additions & 1 deletion crates/events/src/enclave_event/e3_requested.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use crate::{E3id, Seed};
use actix::Message;
use e3_fhe_params::BfvPreset;
use e3_utils::utility_types::ArcBytes;
use serde::{Deserialize, Serialize};
use std::fmt::{self, Display};
Expand All @@ -26,7 +27,11 @@ pub struct E3Requested {
pub error_size: ArcBytes,
/// The number of smudging noise per ciphertext.
pub esi_per_ct: usize,
/// The FHE parameters
/// The threshold BFV preset selected on-chain. The DKG counterpart is
/// derived automatically via `BfvPreset::dkg_counterpart()`.
pub params_preset: BfvPreset,
/// ABI-encoded BFV parameters (derived from `params_preset`).
/// Kept for downstream code that needs the raw bytes (e.g. `TrBFVConfig`).
pub params: ArcBytes,
/// When true, ciphernodes generate wrapper/fold proofs for DKG proof
/// aggregation (public verifiability). When false, wrapper/fold proofs
Expand All @@ -45,6 +50,7 @@ impl Default for E3Requested {
e3_id: E3id::new("99", 0),
error_size: ArcBytes::from_bytes(&[]),
esi_per_ct: 0,
params_preset: BfvPreset::InsecureThreshold512,
params: ArcBytes::from_bytes(&[]),
seed: Seed([0u8; 32]),
threshold_m: 0,
Expand Down
28 changes: 19 additions & 9 deletions crates/evm-helpers/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ sol! {
uint256[2] inputWindow;
bytes32 encryptionSchemeId;
address e3Program;
bytes e3ProgramParams;
uint8 paramSet;
bytes customParams;
address decryptionVerifier;
address pkVerifier;
Expand All @@ -71,7 +71,7 @@ sol! {
CommitteeSize committeeSize;
uint256[2] inputWindow;
address e3Program;
bytes e3ProgramParams;
uint8 paramSet;
bytes computeProviderParams;
bytes customParams;
bool proofAggregationEnabled;
Expand Down Expand Up @@ -129,6 +129,7 @@ sol! {
function publishCiphertextOutput(uint256 e3Id, bytes calldata ciphertextOutput, bytes calldata proof) external returns (bool success);
function publishPlaintextOutput(uint256 e3Id, bytes calldata data, bytes calldata proof, bytes calldata foldProof) external returns (bool success);
function getE3(uint256 e3Id) external view returns (E3 memory e3);
function paramSetRegistry(uint8 paramSet) external view returns (bytes memory encodedParams);
function getE3Quote(E3RequestParams memory request) external view returns (uint256 fee);
function getE3Stage(uint256 e3Id) external view returns (E3Stage stage);
function getFailureReason(uint256 e3Id) external view returns (FailureReason reason);
Expand Down Expand Up @@ -156,10 +157,10 @@ pub trait EnclaveRead {
/// Get the fee quote for an E3 request
async fn get_e3_quote(
&self,
commitee_size: CommitteeSize,
committee_size: CommitteeSize,
input_window: [U256; 2],
e3_program: Address,
e3_params: Bytes,
param_set: u8,
compute_provider_params: Bytes,
proof_aggregation_enabled: bool,
) -> Result<U256>;
Expand All @@ -173,6 +174,9 @@ pub trait EnclaveRead {
async fn get_deadlines(&self, e3_id: U256) -> Result<E3Deadlines>;

async fn get_timeout_config(&self) -> Result<E3TimeoutConfig>;

/// Look up the ABI-encoded BFV parameters for a param set index
async fn get_param_set_registry(&self, param_set: u8) -> Result<Bytes>;
}

/// Trait for write operations on the Enclave contract
Expand All @@ -184,7 +188,7 @@ pub trait EnclaveWrite {
committee_size: CommitteeSize,
input_window: [U256; 2],
e3_program: Address,
e3_params: Bytes,
param_set: u8,
compute_provider_params: Bytes,
custom_params: Bytes,
proof_aggregation_enabled: bool,
Expand Down Expand Up @@ -372,15 +376,15 @@ where
committee_size: CommitteeSize,
input_window: [U256; 2],
e3_program: Address,
e3_params: Bytes,
param_set: u8,
compute_provider_params: Bytes,
proof_aggregation_enabled: bool,
) -> Result<U256> {
let e3_request = E3RequestParams {
committeeSize: committee_size,
inputWindow: input_window,
e3Program: e3_program,
e3ProgramParams: e3_params,
paramSet: param_set,
computeProviderParams: compute_provider_params,
customParams: Bytes::new(),
proofAggregationEnabled: proof_aggregation_enabled,
Expand Down Expand Up @@ -420,6 +424,12 @@ where
let config = contract.getTimeoutConfig().call().await?;
Ok(config)
}

async fn get_param_set_registry(&self, param_set: u8) -> Result<Bytes> {
let contract = Enclave::new(self.contract_address, &self.provider);
let params = contract.paramSetRegistry(param_set).call().await?;
Ok(params)
}
}

// Implement EnclaveWrite only for contracts with ReadWrite marker
Expand All @@ -430,7 +440,7 @@ impl EnclaveWrite for EnclaveContract<ReadWrite> {
committee_size: CommitteeSize,
input_window: [U256; 2],
e3_program: Address,
e3_params: Bytes,
param_set: u8,
compute_provider_params: Bytes,
custom_params: Bytes,
proof_aggregation_enabled: bool,
Expand All @@ -448,7 +458,7 @@ impl EnclaveWrite for EnclaveContract<ReadWrite> {
committeeSize: committee_size,
inputWindow: input_window,
e3Program: e3_program,
e3ProgramParams: e3_params.clone(),
paramSet: param_set,
computeProviderParams: compute_provider_params.clone(),
customParams: custom_params.clone(),
proofAggregationEnabled: proof_aggregation_enabled,
Expand Down
2 changes: 1 addition & 1 deletion crates/evm-helpers/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ sol! {
uint256[2] inputWindow;
bytes32 encryptionSchemeId;
IE3Program e3Program;
bytes e3ProgramParams;
uint8 paramSet;
bytes customParams;
IDecryptionVerifier decryptionVerifier;
IPkVerifier pkVerifier;
Expand Down
6 changes: 4 additions & 2 deletions crates/evm-helpers/tests/fixtures/fake_enclave.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ contract FakeEnclave {
event PlaintextOutputPublished(uint256 indexed e3Id, bytes plaintextOutput, bytes proof);
event CommitteePublished(uint256 indexed e3Id, address[] nodes, bytes publicKey, bytes proof);

mapping(uint8 => bytes) public paramSetRegistry;

// Emit InputPublished event with passed test data
function emitInputPublished(uint256 e3Id, bytes memory data, uint256 inputHash, uint256 index) public {
emit InputPublished(e3Id, data, inputHash, index);
Expand Down Expand Up @@ -42,7 +44,7 @@ contract FakeEnclave {
encryptionSchemeId: bytes32(keccak256("AES-256-GCM")),
e3Program: 0x7F3E4df648B8Cb96C1D343be976b91B97CaD5c21,
decryptionVerifier: 0x4B0D8c2E5f7a6c832f8b16d3aB0e7F5d9E9B24b1,
e3ProgramParams: abi.encode(42, "testParams"),
paramSet: 0,
customParams: abi.encode("custom_params"),
committeePublicKey: bytes32(keccak256("committee_public_key")),
ciphertextOutput: bytes32(keccak256("encrypted_data")),
Expand All @@ -58,7 +60,7 @@ struct E3 {
uint256[2] inputWindow;
bytes32 encryptionSchemeId;
address e3Program;
bytes e3ProgramParams;
uint8 paramSet;
bytes customParams;
address decryptionVerifier;
bytes32 committeePublicKey;
Expand Down
Loading
Loading