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: 2 additions & 0 deletions Cargo.lock

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

15 changes: 15 additions & 0 deletions circuits/lib/src/configs/committee/micro.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: LGPL-3.0-only
//
// This file is provided WITHOUT ANY WARRANTY;
// without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.

/// Currently defaults to just small committee size.
/// In the future, we will add more committee sizes.

/// Number of parties.
pub global N_PARTIES: u32 = 3;
/// Threshold.
pub global T: u32 = 1;
/// Number of honest parties.
pub global H: u32 = 3;
1 change: 1 addition & 0 deletions circuits/lib/src/configs/committee/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
// or FITNESS FOR A PARTICULAR PURPOSE.

pub mod small;
pub mod micro;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
2 changes: 1 addition & 1 deletion circuits/lib/src/configs/default/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Unico punto in cui si cambia il param-set: re-esporta insecure o production
// (in futuro altri param-set). I circuiti usano tutti lib::configs::default::*.

pub use super::committee::small::{H, N_PARTIES, T};
pub use super::committee::micro::{H, N_PARTIES, T};
Comment thread
ctrlc03 marked this conversation as resolved.
pub use super::insecure::dkg;
pub use super::insecure::threshold;

Expand Down
14 changes: 3 additions & 11 deletions circuits/lib/src/configs/insecure/dkg.nr
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,8 @@ pk (CIRCUIT 0)
pub global PK_BIT_PK: u32 = 50;

pub global PARITY_MATRIX: [[[Field; N_PARTIES + 1]; N_PARTIES - T]; L_THRESHOLD] = [
[
[68719403008, 3, 68719403006, 1, 0, 0],
[68719403006, 8, 68719403003, 0, 1, 0],
[68719403003, 15, 68719402999, 0, 0, 1],
],
[
[68719230976, 3, 68719230974, 1, 0, 0],
[68719230974, 8, 68719230971, 0, 1, 0],
[68719230971, 15, 68719230967, 0, 0, 1],
],
[[1, 68719403007, 1, 0], [2, 68719403006, 0, 1]],
[[1, 68719230975, 1, 0], [2, 68719230974, 0, 1]],
];

/************************************
Expand All @@ -60,7 +52,7 @@ share_computation_e_sm (CIRCUIT 2b)
************************************/

// share_computation_e_sm - bit parameters
pub global SHARE_COMPUTATION_E_SM_BIT_SECRET: u32 = 24;
pub global SHARE_COMPUTATION_E_SM_BIT_SECRET: u32 = 23;

// verify_shares - configs
pub global SHARE_COMPUTATION_E_SM_CONFIGS: ShareComputationConfigs<L_THRESHOLD> =
Expand Down
24 changes: 4 additions & 20 deletions circuits/lib/src/configs/secure/dkg.nr
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,10 @@ pk (CIRCUIT 0)
pub global PK_BIT_PK: u32 = 56;

pub global PARITY_MATRIX: [[[Field; N_PARTIES + 1]; N_PARTIES - T]; L_THRESHOLD] = [
[
[2251799822204928, 3, 2251799822204926, 1, 0, 0],
[2251799822204926, 8, 2251799822204923, 0, 1, 0],
[2251799822204923, 15, 2251799822204919, 0, 0, 1],
],
[
[4503599627763712, 3, 4503599627763710, 1, 0, 0],
[4503599627763710, 8, 4503599627763707, 0, 1, 0],
[4503599627763707, 15, 4503599627763703, 0, 0, 1],
],
[
[4503599631433728, 3, 4503599631433726, 1, 0, 0],
[4503599631433726, 8, 4503599631433723, 0, 1, 0],
[4503599631433723, 15, 4503599631433719, 0, 0, 1],
],
[
[4503599634579456, 3, 4503599634579454, 1, 0, 0],
[4503599634579454, 8, 4503599634579451, 0, 1, 0],
[4503599634579451, 15, 4503599634579447, 0, 0, 1],
],
[[1, 2251799822204927, 1, 0], [2, 2251799822204926, 0, 1]],
[[1, 4503599627763711, 1, 0], [2, 4503599627763710, 0, 1]],
[[1, 4503599631433727, 1, 0], [2, 4503599631433726, 0, 1]],
[[1, 4503599634579455, 1, 0], [2, 4503599634579454, 0, 1]],
];
/************************************
-------------------------------------
Expand Down
1 change: 1 addition & 0 deletions crates/evm-helpers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ alloy.workspace = true
anyhow.workspace = true
async-trait.workspace = true
eyre.workspace = true
serde.workspace = true
futures.workspace = true
futures-util.workspace = true
once_cell.workspace = true
Expand Down
25 changes: 17 additions & 8 deletions crates/evm-helpers/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use alloy::{
use async_trait::async_trait;
use eyre::Result;
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use std::marker::PhantomData;
use std::sync::Arc;
use tokio::sync::Mutex;
Expand All @@ -38,10 +39,18 @@ where
}

sol! {
#[derive(Debug, Serialize, Deserialize)]
enum CommitteeSize {
Micro,
Small,
Medium,
Large,
}
Comment thread
ctrlc03 marked this conversation as resolved.

#[derive(Debug)]
struct E3 {
uint256 seed;
uint32[2] threshold;
CommitteeSize committeeSize;
uint256 requestBlock;
uint256[2] inputWindow;
bytes32 encryptionSchemeId;
Expand All @@ -57,7 +66,7 @@ sol! {

#[derive(Debug)]
struct E3RequestParams {
uint32[2] threshold;
CommitteeSize committeeSize;
uint256[2] inputWindow;
address e3Program;
bytes e3ProgramParams;
Expand Down Expand Up @@ -157,7 +166,7 @@ pub trait EnclaveRead {
/// Get the fee quote for an E3 request
async fn get_e3_quote(
&self,
threshold: [u32; 2],
commitee_size: CommitteeSize,
input_window: [U256; 2],
e3_program: Address,
e3_params: Bytes,
Expand All @@ -181,7 +190,7 @@ pub trait EnclaveWrite {
/// Request a new E3
async fn request_e3(
&self,
threshold: [u32; 2],
committee_size: CommitteeSize,
input_window: [U256; 2],
e3_program: Address,
e3_params: Bytes,
Expand Down Expand Up @@ -385,14 +394,14 @@ where

async fn get_e3_quote(
&self,
threshold: [u32; 2],
committee_size: CommitteeSize,
input_window: [U256; 2],
e3_program: Address,
e3_params: Bytes,
compute_provider_params: Bytes,
) -> Result<U256> {
let e3_request = E3RequestParams {
threshold,
committeeSize: committee_size,
inputWindow: input_window,
e3Program: e3_program,
e3ProgramParams: e3_params,
Expand Down Expand Up @@ -441,7 +450,7 @@ where
impl EnclaveWrite for EnclaveContract<ReadWrite> {
async fn request_e3(
&self,
threshold: [u32; 2],
committee_size: CommitteeSize,
input_window: [U256; 2],
e3_program: Address,
e3_params: Bytes,
Expand All @@ -458,7 +467,7 @@ impl EnclaveWrite for EnclaveContract<ReadWrite> {
let e3_id = contract.nexte3Id().call().await?;

let e3_request = E3RequestParams {
threshold,
committeeSize: committee_size,
inputWindow: input_window,
e3Program: e3_program,
e3ProgramParams: e3_params.clone(),
Expand Down
10 changes: 9 additions & 1 deletion crates/evm-helpers/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,18 @@ sol! {
function verifyDecryption(bytes data) external view returns (bool);
}

#[derive(Debug)]
enum CommitteeSize {
Micro,
Small,
Medium,
Large,
}

#[derive(Debug)]
struct E3 {
uint256 seed;
uint32[2] threshold;
CommitteeSize committeeSize;
uint256 requestBlock;
uint256[2] inputWindow;
bytes32 encryptionSchemeId;
Expand Down
1 change: 1 addition & 0 deletions crates/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ e3-fhe-params = { workspace = true }
e3-sortition = { workspace = true }
e3-trbfv = { workspace = true }
e3-utils = { workspace = true }
e3-zk-helpers = { workspace = true }
futures-util = { workspace = true }
hex = { workspace = true }
num-bigint = { workspace = true }
Expand Down
47 changes: 28 additions & 19 deletions crates/evm/src/enclave_sol_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use e3_events::{E3Failed, E3Stage, E3StageChanged, FailureReason};
use e3_fhe_params::decode_bfv_params_arc;
use e3_trbfv::helpers::calculate_error_size;
use e3_utils::ArcBytes;
use e3_zk_helpers::CiphernodesCommitteeSize;
use num_bigint::BigUint;
use tracing::{error, info, trace, warn};

Expand All @@ -26,11 +27,22 @@ sol!(

struct E3RequestedWithChainId(pub IEnclave::E3Requested, pub u64);

impl From<E3RequestedWithChainId> for e3_events::E3Requested {
fn from(value: E3RequestedWithChainId) -> Self {
let params_bytes = value.0.e3.e3ProgramParams.to_vec();
let threshold_m = value.0.e3.threshold[0] as usize;
let threshold_n = value.0.e3.threshold[1] as usize;
impl E3RequestedWithChainId {
fn try_into_e3_requested(self) -> anyhow::Result<e3_events::E3Requested> {
let params_bytes = self.0.e3.e3ProgramParams.to_vec();

// Derive threshold values from committee size enum
let committee_size = match self.0.e3.committeeSize {
0 => CiphernodesCommitteeSize::Micro,
1 => CiphernodesCommitteeSize::Small,
2 => CiphernodesCommitteeSize::Medium,
3 => CiphernodesCommitteeSize::Large,
other => anyhow::bail!("Unsupported committee size: {}", other),
};
let committee = committee_size.values();
let threshold_m = committee.threshold;
let threshold_n = committee.n;

let params_arc = decode_bfv_params_arc(&params_bytes).expect("Failed to decode BFV params");

// TODO: These should be delivered from the e3_program contract
Expand Down Expand Up @@ -66,22 +78,15 @@ impl From<E3RequestedWithChainId> for e3_events::E3Requested {
}
};

e3_events::E3Requested {
Ok(e3_events::E3Requested {
params: ArcBytes::from_bytes(&params_bytes),
threshold_m,
threshold_n,
seed: value.0.e3.seed.into(),
seed: self.0.e3.seed.into(),
error_size,
esi_per_ct,
e3_id: E3id::new(value.0.e3Id.to_string(), value.1),
}
}
}

impl From<E3RequestedWithChainId> for EnclaveEventData {
fn from(value: E3RequestedWithChainId) -> Self {
let payload: e3_events::E3Requested = value.into();
payload.into()
e3_id: E3id::new(self.0.e3Id.to_string(), self.1),
})
}
}

Expand Down Expand Up @@ -183,9 +188,13 @@ pub fn extractor(data: &LogData, topic: Option<&B256>, chain_id: u64) -> Option<
error!("Error parsing event E3Requested after topic matched!");
return None;
};
Some(EnclaveEventData::from(E3RequestedWithChainId(
event, chain_id,
)))
match E3RequestedWithChainId(event, chain_id).try_into_e3_requested() {
Ok(payload) => Some(payload.into()),
Err(e) => {
error!("Error processing E3Requested event: {}", e);
None
}
}
}
Some(&IEnclave::CiphertextOutputPublished::SIGNATURE_HASH) => {
let Ok(event) = IEnclave::CiphertextOutputPublished::decode_log_data(data) else {
Expand Down
2 changes: 1 addition & 1 deletion crates/indexer/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ impl<S: DataStore, R: ProviderType> EnclaveIndexer<S, R> {
request_block,
seed,
input_window,
threshold: e3.threshold,
committee_size: e3.committeeSize,
requester: e3.requester.to_string(),
};

Expand Down
3 changes: 2 additions & 1 deletion crates/indexer/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.

use e3_evm_helpers::contracts::CommitteeSize;
use serde::{Deserialize, Serialize};

// This correlates with the information from the contract
Expand All @@ -23,6 +24,6 @@ pub struct E3 {
pub request_block: u64,
pub seed: [u8; 32],
pub input_window: [u64; 2],
pub threshold: [u32; 2],
pub committee_size: CommitteeSize,
pub requester: String,
}
15 changes: 12 additions & 3 deletions crates/indexer/tests/fixtures/fake_enclave.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ contract FakeEnclave {
function getE3(uint256 _e3Id) external view returns (E3 memory e3) {
e3 = E3({
seed: 123456789012,
threshold: [uint32(2), uint32(3)],
committeeSize: CommitteeSize.Micro,
requestBlock: 18750000,
inputWindow: [uint256(18750100), uint256(18750200)],
encryptionSchemeId: bytes32(keccak256("AES-256-GCM")),
Expand All @@ -46,14 +46,22 @@ contract FakeEnclave {
customParams: abi.encode("custom_params"),
committeePublicKey: bytes32(keccak256("committee_public_key")),
ciphertextOutput: bytes32(keccak256("encrypted_data")),
plaintextOutput: abi.encode("decrypted_result")
plaintextOutput: abi.encode("decrypted_result"),
requester: 0xdead000000000000000000000000000000000001
});
}
}

enum CommitteeSize {
Micro,
Small,
Medium,
Large
}

struct E3 {
uint256 seed;
uint32[2] threshold;
CommitteeSize committeeSize;
uint256 requestBlock;
uint256[2] inputWindow;
bytes32 encryptionSchemeId;
Expand All @@ -64,4 +72,5 @@ struct E3 {
bytes32 committeePublicKey;
bytes32 ciphertextOutput;
bytes plaintextOutput;
address requester;
}
Loading
Loading