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
38 changes: 22 additions & 16 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/aggregator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ e3-evm = { workspace = true }
e3-fhe = { workspace = true }
e3-multithread = { workspace = true }
e3-trbfv = { workspace = true }
e3-bfv-helpers = { workspace = true }
e3-request = { workspace = true }
e3-sortition = { workspace = true }
e3-utils = { workspace = true }
Expand Down
9 changes: 9 additions & 0 deletions crates/aggregator/src/publickey_aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use actix::prelude::*;
use anyhow::Result;
use e3_bfv_helpers::client::compute_pk_commitment;
use e3_data::Persistable;
use e3_events::{
prelude::*, BusHandle, Die, E3id, EnclaveEvent, EnclaveEventData, KeyshareCreated, OrderedSet,
Expand Down Expand Up @@ -181,6 +182,13 @@ impl Handler<ComputeAggregate> for PublicKeyAggregator {
keyshares: msg.keyshares,
})?;

let public_key_hash = compute_pk_commitment(
pubkey.clone(),
self.fhe.params.degree(),
self.fhe.params.plaintext(),
self.fhe.params.moduli().to_vec(),
)?;

// Update the local state
self.set_pubkey(pubkey)?;

Expand All @@ -194,6 +202,7 @@ impl Handler<ComputeAggregate> for PublicKeyAggregator {
info!("Sending PublicKeyAggregated...");
let event = PublicKeyAggregated {
pubkey,
public_key_hash,
e3_id: msg.e3_id,
nodes,
};
Expand Down
41 changes: 41 additions & 0 deletions crates/bfv-helpers/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// or FITNESS FOR A PARTICULAR PURPOSE.

use crate::build_bfv_params_arc;
use crate::utils::greco::bfv_public_key_to_greco;
use anyhow::{anyhow, Result};
use fhe::bfv::{Encoding, Plaintext, PublicKey};
use fhe::Error as FheError;
Expand Down Expand Up @@ -129,6 +130,46 @@ where
})
}

pub fn compute_pk_commitment(
public_key: Vec<u8>,
degree: usize,
plaintext_modulus: u64,
moduli: Vec<u64>,
) -> Result<[u8; 32]> {
use shared::commitments::compute_pk_commitment as _compute_pk_commitment;
use shared::template::calculate_bit_width;

let params = build_bfv_params_arc(degree, plaintext_modulus, &moduli, None);

let public_key = PublicKey::from_bytes(&public_key, &params)
.map_err(|e| anyhow!("Error deserializing public key: {}", e))?;

let (_, bounds) = GrecoBounds::compute(&params, 0)?;
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_pk_commitment(&pk0is, &pk1is, bit_pk);

let bytes = commitment_bigint.to_bytes_be().1;

if bytes.len() > 32 {
return Err(anyhow!(
"Commitment must be at most 32 bytes, got {}",
bytes.len()
));
}

let mut padded_bytes = vec![0u8; 32];
let start_idx = 32 - bytes.len();
padded_bytes[start_idx..].copy_from_slice(&bytes);

let public_key_hash: [u8; 32] = padded_bytes
.try_into()
.map_err(|_| anyhow!("Failed to convert padded bytes to array"))?;

Ok(public_key_hash)
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

#[cfg(test)]
mod tests {
use crate::BfvParamSets;
Expand Down
Loading
Loading