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
71 changes: 42 additions & 29 deletions Cargo.lock

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

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ members = [
"crates/utils",
"crates/wasm",
"crates/parity-matrix",
"crates/polynomial"
"crates/polynomial",
"crates/zk-helpers"
]
exclude = [
"examples/CRISP",
Expand Down Expand Up @@ -93,11 +94,14 @@ e3-net = { version = "0.1.7", path = "./crates/net" }
e3-compute-provider = { version = "0.1.7", path = "./crates/compute-provider" }
e3-sortition = { version = "0.1.7", path = "./crates/sortition" }
e3-program-server = { version = "0.1.7", path = "./crates/program-server" }
e3-polynomial = { version = "0.1.7", path = "./crates/polynomial" }
e3-support-scripts = { version = "0.1.7", path = "./crates/support-scripts" }
e3-test-helpers = { version = "0.1.7", path = "./crates/test-helpers" }
e3-tests = { version = "0.1.7", path = "./crates/tests" }
e3-trbfv = { version = "0.1.7", path = "./crates/trbfv" }
e3-utils = { version = "0.1.7", path = "./crates/utils" }
e3-safe = { version = "0.1.7", path = "./crates/safe" }
e3-zk-helpers = { version = "0.1.7", path = "./crates/zk-helpers" }

actix = "=0.13.5"
actix-web = "=4.11.0"
Expand All @@ -111,6 +115,8 @@ alloy-primitives = { version = "=1.3.0", default-features = false, features = [
alloy-sol-types = "=1.3.0"
alloy-dyn-abi = "=1.3.0"
argon2 = "=0.5.3"
ark-ff = "0.5.0"
ark-bn254 = "0.5.0"
anyhow = "=1.0.98"
async-std = { version = "=1.13.1", features = ["attributes"] }
async-trait = "=0.1.88"
Expand Down
23 changes: 20 additions & 3 deletions circuits/lib/src/math/commitments.nr
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,14 @@ pub global DS_PK_AGG: [u8; 64] = [
];
// Domain separator - "AGGREGATION"
pub global DS_AGGREGATION: [u8; 64] = [
0x41, 0x47, 0x47, 0x72, 0x65, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00,
0x41, 0x47, 0x47, 0x52, 0x45, 0x47, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
];
// Domain separator - "CIPHERTEXT"
pub global DS_CIPHERTEXT: [u8; 64] = [
0x43, 0x49, 0x50, 0x48, 0x45, 0x52, 0x54, 0x45, 0x58, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand All @@ -74,14 +81,14 @@ pub global DS_CLG_ENC_BFV: [u8; 64] = [
];
// Domain separator - "CLG_GRECO"
pub global DS_CLG_GRECO: [u8; 64] = [
0x43, 0x4c, 0x47, 0x5f, 0x47, 0x72, 0x65, 0x63, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x43, 0x4c, 0x47, 0x5f, 0x47, 0x52, 0x45, 0x43, 0x4f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
];
// Domain separator - "CLG_DEC_SHARE"
pub global DS_CLG_DEC_SHARE: [u8; 64] = [
0x43, 0x4c, 0x47, 0x5f, 0x44, 0x65, 0x63, 0x53, 0x68, 0x61, 0x72, 0x65, 0x00, 0x00, 0x00, 0x00,
0x43, 0x4c, 0x47, 0x5f, 0x44, 0x45, 0x43, 0x5f, 0x53, 0x48, 0x41, 0x52, 0x45, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand Down Expand Up @@ -191,6 +198,16 @@ pub fn compute_aggregation_commitment(payload: Vec<Field>) -> Field {
compute_safe(DS_AGGREGATION, payload, [0x80000000 | payload.len(), 1]).get(0)
}

pub fn compute_ciphertext_commitment<let N: u32, let L: u32, let BIT_CT: u32>(
ct0: [Polynomial<N>; L],
ct1: [Polynomial<N>; L],
) -> Field {
let mut payload = multiple_polynomial_payload::<N, L, BIT_CT>(Vec::new(), ct0);
payload = multiple_polynomial_payload::<N, L, BIT_CT>(payload, ct1);

compute_commitments(payload, DS_CIPHERTEXT, [0x80000000 | payload.len(), 1]).get(0)
}

/// COMMITMENTS FOR CHALLENGES

pub fn compute_pk_trbfv_challenge<let L: u32>(payload: Vec<Field>) -> Vec<Field> {
Expand Down
1 change: 1 addition & 0 deletions crates/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ COPY crates/tests/Cargo.toml ./tests/Cargo.toml
COPY crates/trbfv/Cargo.toml ./trbfv/Cargo.toml
COPY crates/utils/Cargo.toml ./utils/Cargo.toml
COPY crates/wasm/Cargo.toml ./wasm/Cargo.toml
COPY crates/zk-helpers/Cargo.toml ./zk-helpers/Cargo.toml

RUN echo 'fn main() { println!("cargo:warning=dependency cache build"); }' > ./entrypoint/build.rs
RUN echo 'fn main() { println!("cargo:warning=dependency cache build"); }' > ./cli/build.rs
Expand Down
2 changes: 1 addition & 1 deletion crates/bfv-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ fhe.workspace = true
fhe-traits.workspace = true
greco = { package = "zkfhe-greco", git = "https://github.com/gnosisguild/zkfhe-generator" }
rand.workspace = true
shared = { package = "zkfhe-shared", git = "https://github.com/gnosisguild/zkfhe-generator" }
thiserror = { workspace = true }
e3-zk-helpers = { workspace = true }
10 changes: 5 additions & 5 deletions crates/bfv-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
use anyhow::{anyhow, Result};
use e3_fhe_params::build_bfv_params_arc;
use e3_greco_helpers::{bfv_ciphertext_to_greco, bfv_public_key_to_greco};
use e3_zk_helpers::commitments::{compute_ciphertext_commitment, compute_pk_agg_commitment};
use e3_zk_helpers::utils::calculate_bit_width;
use fhe::bfv::{Ciphertext, Encoding, Plaintext, PublicKey};
use fhe::Error as FheError;
use fhe_traits::{DeserializeParametrized, FheEncoder, FheEncrypter, Serialize};
use greco::bounds::GrecoBounds;
use greco::vectors::GrecoVectors;
use rand::thread_rng;
use shared::commitments::compute_poly_commitment;
use shared::template::calculate_bit_width;

/// Encrypt some data using BFV homomorphic encryption
///
Expand Down Expand Up @@ -109,7 +109,7 @@ where

let (_, bounds) = GrecoBounds::compute(&params, 0)?;

let bit_pk = shared::template::calculate_bit_width(&bounds.pk_bounds[0].to_string())?;
let bit_pk = calculate_bit_width(&bounds.pk_bounds[0].to_string())?;

// Create Greco input validation ZK proof
let input_val_vectors = GrecoVectors::compute(
Expand Down Expand Up @@ -147,7 +147,7 @@ pub fn compute_pk_commitment(
let bit_pk = calculate_bit_width(&bounds.pk_bounds[0].to_string())?;

let (pk0is, pk1is) = bfv_public_key_to_greco(&public_key, &params);
let commitment_bigint = compute_poly_commitment(&pk0is, &pk1is, bit_pk);
let commitment_bigint = compute_pk_agg_commitment(&pk0is, &pk1is, bit_pk);

let bytes = commitment_bigint.to_bytes_be().1;

Expand Down Expand Up @@ -185,7 +185,7 @@ pub fn compute_ct_commitment(
let (_, bounds) = GrecoBounds::compute(&params, 0)?;
let bit_ct = calculate_bit_width(&bounds.pk_bounds[0].to_string())?;

let commitment_bigint = compute_poly_commitment(&ct0is, &ct1is, bit_ct);
let commitment_bigint = compute_ciphertext_commitment(&ct0is, &ct1is, bit_ct);

let bytes = commitment_bigint.to_bytes_be().1;

Expand Down
1 change: 0 additions & 1 deletion crates/fhe-params/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ repository = "https://github.com/gnosisguild/enclave/crates/fhe-params"
fhe = { workspace = true }
num-bigint = { workspace = true }
thiserror = { workspace = true }
shared = { package = "zkfhe-shared", git = "https://github.com/gnosisguild/zkfhe-generator" }
alloy-dyn-abi = { workspace = true, optional = true }
alloy-primitives = { workspace = true, optional = true }

Expand Down
5 changes: 5 additions & 0 deletions crates/fhe-params/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,9 @@ pub mod defaults {
/// when variance is not specified. Both variance() and error1_variance default to this value.
pub const VARIANCE: usize = 10;
pub const ERROR1_VARIANCE: u32 = 10;

/// Default insecure security parameter (λ).
pub const DEFAULT_INSECURE_LAMBDA: usize = 2;
/// Default secure security parameter (λ).
pub const DEFAULT_SECURE_LAMBDA: usize = 80;
}
15 changes: 6 additions & 9 deletions crates/fhe-params/src/presets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
use crate::builder::build_pair_for_preset;
use crate::builder::{build_bfv_params_from_set, build_bfv_params_from_set_arc};
use crate::constants::{
defaults::DEFAULT_INSECURE_LAMBDA,
defaults::DEFAULT_SECURE_LAMBDA,
insecure_512,
search_defaults::{B, B_CHI},
secure_8192,
};
use shared::{SecurityLevel, DEFAULT_INSECURE_LAMBDA, DEFAULT_SECURE_LAMBDA};
use std::sync::Arc;
use thiserror::Error as ThisError;

Expand Down Expand Up @@ -64,8 +65,6 @@ pub enum BfvPreset {
pub struct PresetMetadata {
/// The canonical name of the preset (e.g., "INSECURE_THRESHOLD_BFV_512")
pub name: &'static str,
/// Security level classification (Secure if λ ≥ 80, Insecure otherwise)
pub security_level: SecurityLevel,
/// LWE dimension (d) - the degree of the polynomial ring, must be a power of 2
///
/// This determines the size of the polynomial ring R_q = Z_q[X]/(X^d + 1).
Expand Down Expand Up @@ -221,14 +220,12 @@ impl BfvPreset {
match self {
BfvPreset::InsecureThresholdBfv512 | BfvPreset::InsecureDkg512 => PresetMetadata {
name: self.name(),
security_level: SecurityLevel::from_lambda(DEFAULT_INSECURE_LAMBDA),
degree: insecure_512::DEGREE,
num_parties: insecure_512::NUM_PARTIES,
lambda: DEFAULT_INSECURE_LAMBDA,
},
BfvPreset::SecureThresholdBfv8192 | BfvPreset::SecureDkg8192 => PresetMetadata {
name: self.name(),
security_level: SecurityLevel::from_lambda(DEFAULT_SECURE_LAMBDA),
degree: secure_8192::DEGREE,
num_parties: secure_8192::NUM_PARTIES,
lambda: DEFAULT_SECURE_LAMBDA,
Expand Down Expand Up @@ -364,13 +361,13 @@ mod tests {
let metadata = insecure.metadata();
assert_eq!(metadata.degree, insecure_512::DEGREE);
assert_eq!(metadata.num_parties, insecure_512::NUM_PARTIES);
assert_eq!(metadata.lambda, shared::DEFAULT_INSECURE_LAMBDA);
assert_eq!(metadata.lambda, DEFAULT_INSECURE_LAMBDA);

let secure = BfvPreset::SecureThresholdBfv8192;
let metadata = secure.metadata();
assert_eq!(metadata.degree, secure_8192::DEGREE);
assert_eq!(metadata.num_parties, secure_8192::NUM_PARTIES);
assert_eq!(metadata.lambda, shared::DEFAULT_SECURE_LAMBDA);
assert_eq!(metadata.lambda, DEFAULT_SECURE_LAMBDA);
}

#[test]
Expand All @@ -380,14 +377,14 @@ mod tests {
assert_eq!(defaults.n, insecure_512::threshold::SEARCH_N);
assert_eq!(defaults.k, insecure_512::threshold::SEARCH_K);
assert_eq!(defaults.z, insecure_512::threshold::SEARCH_Z);
assert_eq!(defaults.lambda, shared::DEFAULT_INSECURE_LAMBDA as u32);
assert_eq!(defaults.lambda, DEFAULT_INSECURE_LAMBDA as u32);

let preset = BfvPreset::SecureThresholdBfv8192;
let defaults = preset.search_defaults().unwrap();
assert_eq!(defaults.n, secure_8192::threshold::SEARCH_N);
assert_eq!(defaults.k, secure_8192::threshold::SEARCH_K);
assert_eq!(defaults.z, secure_8192::threshold::SEARCH_Z);
assert_eq!(defaults.lambda, shared::DEFAULT_SECURE_LAMBDA as u32);
assert_eq!(defaults.lambda, DEFAULT_SECURE_LAMBDA as u32);

// DKG presets don't have search defaults
assert!(BfvPreset::InsecureDkg512.search_defaults().is_none());
Expand Down
2 changes: 1 addition & 1 deletion crates/greco-helpers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repository = "https://github.com/gnosisguild/enclave/crates/greco-helpers"
fhe = { workspace = true }
fhe-math = { git = "https://github.com/gnosisguild/fhe.rs" }
num-bigint = { workspace = true }
shared = { package = "zkfhe-shared", git = "https://github.com/gnosisguild/zkfhe-generator" }
e3-zk-helpers = { workspace = true }

[dev-dependencies]
e3-fhe-params = { workspace = true }
Expand Down
Loading
Loading