Skip to content
Open
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 circuits/bin/synchronized/threshold/Nargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[workspace]
members = ["pk_generation", "pk_aggregation", "share_decryption"]
members = ["pk_generation", "pk_aggregation", "share_decryption", "decrypted_shares_aggregation"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "decrypted_shares_aggregation"
type = "bin"
authors = []

[dependencies]
lib = { path = "../../../../lib" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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.

use lib::configs::protocol::MAX_MSG_NON_ZERO_COEFFS;
use lib::configs::synchronized::sync_insecure_64::{C6_PUBLIC_FIELDS, L_THRESHOLD, N, T};
use lib::core::synchronized::plaintext_aggregation::execute;

fn main(
rows: pub [[Field; C6_PUBLIC_FIELDS]; T + 1],
message: pub [u64; MAX_MSG_NON_ZERO_COEFFS],
c0: [[u64; N]; L_THRESHOLD],
shares: [[[u64; N]; L_THRESHOLD]; T + 1],
) {
execute(rows, message, c0, shares);
}
5 changes: 5 additions & 0 deletions circuits/lib/src/configs/synchronized/sync_insecure_64.nr
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ pub global PRF_KEY_BITS: u32 = 64;
pub global SHARE_BIT: u32 = 27;
pub global AGGREGATE_BIT: u32 = 26;
pub global C6_NOISE_BOUND: u64 = 255488870400000;
pub global C6_PUBLIC_FIELDS: u32 = 12;
pub global C7_PLAINTEXT_MODULUS: Field = 17000000;
pub global C7_BIT_K: u32 = 33;
pub global C7_BIT_T: u32 = 25;
pub global C7_BIT_Q_TOTAL: u32 = 81;
pub global PK_BIT_PK: u32 = 28;
pub global PK_GENERATION_BIT_EEK: u32 = 5;
pub global PK_GENERATION_BIT_SK: u32 = 1;
Expand Down
1 change: 1 addition & 0 deletions circuits/lib/src/core/synchronized/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ pub mod pk_generation;
pub mod share_computation;
pub mod share_decryption;
pub mod threshold_decryption;
pub mod plaintext_aggregation;
pub mod provenance;
pub mod publication;
95 changes: 95 additions & 0 deletions circuits/lib/src/core/synchronized/plaintext_aggregation.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// 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.

use crate::configs::protocol::MAX_MSG_NON_ZERO_COEFFS as K;
use crate::configs::synchronized::sync_insecure_64::{
C6_PUBLIC_FIELDS, C7_BIT_K, C7_BIT_Q_TOTAL, C7_BIT_T, C7_PLAINTEXT_MODULUS, H, L_THRESHOLD as L,
N, N_PARTIES, QIS_THRESHOLD, SHARE_BIT, T,
};
use crate::core::threshold::decrypted_shares_aggregation::{garner_reconstruct, rounded_decode};
use crate::math::commitments::compute_threshold_decryption_share_commitment;
use crate::math::modulo::U128::reduce_mod_bounded;
use crate::math::polynomial::Polynomial;
use super::threshold_decryption::component_commitment;

/// `rows` are the *public* statements of the C6 leaves in designated order. The recursive
/// consumer must compare these exact rows (including each SK/bundle anchor) to verified proofs.
pub fn execute(
rows: [[Field; C6_PUBLIC_FIELDS]; T + 1],
message: [u64; K],
c0: [[u64; N]; L],
shares: [[[u64; N]; L]; T + 1],
) {
std::static_assert(T + 1 <= H, "designated set exceeds H");
std::static_assert(K <= N, "message exceeds ring degree");
std::static_assert(
C6_PUBLIC_FIELDS == H + 10,
"unexpected synchronized C6 layout",
);
// Layout: setup[2], owner, roster[H], domain[2], SK, bundle, ct, d, c0.
let first = rows[0];
for i in 0..H {
let id = first[3 + i];
id.assert_max_bit_size::<32>();
assert((id as u32) < N_PARTIES);
if i > 0 {
assert((first[2 + i] as u32) < (id as u32));
}
}
for i in 0..2 {
first[i].assert_max_bit_size::<128>();
first[3 + H + i].assert_max_bit_size::<128>();
}
let c0_commitment = component_commitment(c0);
for s in 0..T + 1 {
let row = rows[s];
assert(row[2] == first[3 + s], "Unexpected designated owner");
assert((row[0] == first[0]) & (row[1] == first[1]), "Mixed C6 setup");
for i in 0..H {
assert(row[3 + i] == first[3 + i], "Mixed C6 roster");
}
for i in 0..2 {
assert(row[3 + H + i] == first[3 + H + i], "Mixed C6 domain");
}
assert(row[7 + H] == first[7 + H], "Mixed C6 ciphertext");
assert(row[9 + H] == c0_commitment, "Wrong C6 c0 opening");
let mut polynomials = [Polynomial::new([0; N]); L];
for l in 0..L {
for j in 0..N {
let r = shares[s][l][j];
assert(r < QIS_THRESHOLD[l] as u64);
polynomials[l].coefficients[j] = r as Field;
}
}
assert(
compute_threshold_decryption_share_commitment::<N, L, SHARE_BIT>(polynomials)
== row[8 + H],
"Wrong C6 share opening",
);
}
let mut q_total: Field = 1;
for q in QIS_THRESHOLD {
q_total *= q;
}
for j in 0..K {
let mut residues = [0; L];
for l in 0..L {
let mut sum = c0[l][j] as Field;
for s in 0..T + 1 {
sum += shares[s][l][j] as Field;
}
residues[l] = reduce_mod_bounded::<SHARE_BIT, C7_BIT_K>(sum, QIS_THRESHOLD[l]);
}
let u = garner_reconstruct::<L, SHARE_BIT, C7_BIT_K>(residues, QIS_THRESHOLD);
let decoded = rounded_decode::<C7_BIT_T, C7_BIT_Q_TOTAL>(
u,
C7_PLAINTEXT_MODULUS,
q_total,
(q_total - 1) / 2,
);
assert(decoded == message[j] as Field, "Decoded plaintext mismatch");
}
}
17 changes: 9 additions & 8 deletions circuits/lib/src/core/synchronized/threshold_decryption.nr
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ fn centered(rows: [[u64; N]; L]) -> [Polynomial<N>; L] {
result
}

pub fn component_commitment(rows: [[u64; N]; L]) -> Field {
compute_multiple_polynomial_commitment_checked::<N, L, AGGREGATE_BIT>(
centered(rows),
DS_CIPHERTEXT,
)
}

fn designated<let R: u32, let S: u32>(owner: u32, roster: [u32; R]) -> ([u32; S], u32) {
assert(S > 0);
assert(S <= R);
Expand Down Expand Up @@ -87,14 +94,8 @@ pub fn execute(
plus[i] = outgoing[roster[row]];
minus[i] = incoming[row];
}
let c0 = compute_multiple_polynomial_commitment_checked::<N, L, AGGREGATE_BIT>(
centered(ct[0]),
DS_CIPHERTEXT,
);
let c1 = compute_multiple_polynomial_commitment_checked::<N, L, AGGREGATE_BIT>(
centered(ct[1]),
DS_CIPHERTEXT,
);
let c0 = component_commitment(ct[0]);
let c1 = component_commitment(ct[1]);
assert(compute_commitment([c0, c1].as_vector(), DS_CIPHERTEXT) == expected_ct);
let mask = prf::mask(ids, ct, QIS_THRESHOLD.map(|q| q as u64), plus, minus);
let weights = lagrange_coefficients::<T + 1, L, SHARE_BIT, SHARE_BIT + 6>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ pub fn lagrange_coefficients<let H: u32, let L: u32, let BIT_Q: u32, let BIT_K:
///
/// This replaces taking `u` as a witness with its own CRT-consistency equation and quotients: `u` is
/// derived here, so there is no quotient to bound and nothing for a prover to choose.
fn garner_reconstruct<let L: u32, let BIT_Q: u32, let BIT_K: u32>(
pub fn garner_reconstruct<let L: u32, let BIT_Q: u32, let BIT_K: u32>(
residues: [Field; L],
qis: [Field; L],
) -> Field {
Expand Down Expand Up @@ -229,7 +229,7 @@ fn garner_reconstruct<let L: u32, let BIT_Q: u32, let BIT_K: u32>(
/// `[0, Q)` is unique, so a wrong hint cannot satisfy both checks below.
///
/// `half` is passed in because the caller already computed it once for every coefficient.
fn rounded_decode<let BIT_T: u32, let BIT_Q_TOTAL: u32>(
pub fn rounded_decode<let BIT_T: u32, let BIT_Q_TOTAL: u32>(
u: Field,
t: Field,
q_total: Field,
Expand Down
14 changes: 9 additions & 5 deletions crates/bfv/threshold/tests/synchronized_dkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ impl Fixture {
}

fn native_at(binding: SetupBinding) -> Result<Self> {
Self::native_with_roster(binding, DEALERS)
}

fn native_with_roster(binding: SetupBinding, roster: [u32; 2]) -> Result<Self> {
let config = Configs::for_profile(PROFILE, CiphernodesCommitteeSize::Minimum)?;
let values = config.committee.values();
let mut rng = ChaCha8Rng::seed_from_u64(245602);
Expand Down Expand Up @@ -161,7 +165,7 @@ impl Fixture {
config.pk_generation.bits.pk_bit,
),
],
prove: DEALERS.contains(&(dealer as u32)),
prove: roster.contains(&(dealer as u32)),
transport_slot: None,
});
let mut packed_commitments = Vec::new();
Expand All @@ -184,7 +188,7 @@ impl Fixture {
})
.collect();
packed_commitments.extend(expected.clone());
if !DEALERS.contains(&(dealer as u32)) {
if !roster.contains(&(dealer as u32)) {
continue;
}
let (encrypted, witnesses) = BfvEncryptedShare::encrypt_extended(
Expand Down Expand Up @@ -245,7 +249,7 @@ impl Fixture {
role: CircuitName::SkShareComputation,
inputs: sharing.to_json(),
outputs: packed_commitments,
prove: DEALERS.contains(&(dealer as u32)),
prove: roster.contains(&(dealer as u32)),
transport_slot: None,
});
}
Expand All @@ -262,14 +266,14 @@ impl Fixture {
&config,
binding,
recipient as u32,
&DEALERS,
&roster,
&sk,
&outgoing[recipient],
&received_keys[recipient],
)?;
let data = share_decryption::Data {
recipient_id: recipient as u32,
dealer_ids: DEALERS.to_vec(),
dealer_ids: roster.to_vec(),
expected_outgoing_root: roots[recipient].clone(),
expected_commitments: message_commitments[recipient].clone(),
packed_shares: messages[recipient].clone().into(),
Expand Down
Loading
Loading