Skip to main content

golden_dkg/
lib.rs

1//! # golden-dkg
2//!
3//! Pure-crypto library implementing the **Golden** non-interactive Distributed Key
4//! Generation protocol from [Bünz, Choi, Komlo (IACR 2025/1924)](https://eprint.iacr.org/2025/1924).
5//!
6//! Golden achieves public verifiability in a single broadcast round using an exponent
7//! Verifiable Random Function (eVRF) built on Diffie-Hellman key exchange. Security
8//! relies only on discrete-log/DDH assumptions over BLS12-381. The output is Shamir
9//! secret shares of a field element `sk` distributed to all participants, together with
10//! a public key `PK = g^sk`.
11//!
12//! ## Protocols
13//!
14//! | Protocol | Module | Description |
15//! |----------|--------|-------------|
16//! | DKG | [`dkg`] | One-round distributed key generation (Section 5, Figure 4) |
17//! | Refresh | [`refresh`] | Proactive share rotation -- same group, rotate shares (Section 5.2) |
18//! | Reshare | [`reshare`] | Membership change -- transfer secret to a new group |
19//!
20//! ## Quick Start
21//!
22//! ```rust,no_run
23//! use golden_dkg::{dkg, types::*};
24//! use std::collections::HashMap;
25//! use ark_bls12_381::G1Affine;
26//! use ark_ff::UniformRand;
27//!
28//! # fn main() -> Result<(), golden_dkg::error::DkgError> {
29//! let mut rng = rand::rngs::OsRng;
30//!
31//! // 1. Each participant generates an identity keypair + proof of knowledge
32//! let alice = Participant::new(1, &mut rng);
33//! let bob = Participant::new(2, &mut rng);
34//!
35//! // 2. Build peer map (in real code, exchange PKs over an authenticated channel)
36//! let mut peers = HashMap::new();
37//! peers.insert(alice.id, alice.pk);
38//! peers.insert(bob.id, bob.pk);
39//!
40//! // 3. Configure the session
41//! let config = DkgConfig {
42//!     n: 2,
43//!     t: 2,
44//!     beta: Scalar::rand(&mut rng),
45//!     session_id: SessionId::random(&mut rng),
46//! };
47//!
48//! // 4. Round 0: each participant creates a dealing
49//! let alice_dealing = dkg::create_dealing(&alice, &config, &peers, &mut rng)?;
50//! let bob_dealing = dkg::create_dealing(&bob, &config, &peers, &mut rng)?;
51//!
52//! // 5. Broadcast dealing.message to all participants (network layer)
53//!
54//! // 6. Verify received dealings (publicly verifiable -- anyone can check)
55//! dkg::verify_dealing(&bob_dealing.message, &peers, &config)?;
56//! dkg::verify_dealing(&alice_dealing.message, &peers, &config)?;
57//!
58//! // 7. Complete: decrypt shares and produce DKG output
59//! let mut alice_received = HashMap::new();
60//! alice_received.insert(bob.id, bob_dealing.message.clone());
61//! let alice_output = dkg::complete(&alice, &alice_dealing, &alice_received, &peers, &config)?;
62//!
63//! // alice_output.public_key  -- the shared group public key PK = g^sk
64//! // alice_output.secret_share -- Alice's secret key share sk_i
65//! // alice_output.public_key_shares -- per-participant public key shares PK_j = g^{sk_j}
66//! # Ok(())
67//! # }
68//! ```
69//!
70//! ## Feature Flags
71//!
72//! | Feature | Description |
73//! |---------|-------------|
74//! | `borsh` | Enable [Borsh](https://borsh.io/) serialization for all message types |
75//!
76//! ## Security Properties
77//!
78//! - **Public verifiability**: all participants (and external observers) can verify
79//!   all dealings non-interactively without any secret information
80//! - **No trusted setup**: transparent proof system via ark-spartan NIZK
81//! - **DL/DDH only**: security relies on discrete-log and decisional Diffie-Hellman
82//!   assumptions (no pairings, no random oracle model for the core protocol)
83//! - **Replay protection**: [`types::SessionId`] nonces prevent replaying old messages
84//! - **Rogue-key protection**: Schnorr proof of knowledge ([`schnorr_pok`]) on PKI
85//!   registration prevents adversarial key choices
86//! - **Secret zeroization**: secret keys are zeroed from memory on drop via
87//!   [`types::SecretScalar`]
88//!
89//! ## Formal Verification
90//!
91//! This crate has multi-layer formal verification covering the paper math, the Rust
92//! implementation, and the bridge between them. See `formal_verification/README.md` for
93//! the full verification chain diagram and detailed status
94//! (`formal_verification/README.md` in the repository root).
95//!
96//! ### Approach
97//!
98//! The verification uses three tools in a "sandwich" architecture:
99//!
100//! **Top layer -- Lean 4 + Mathlib (paper math):** 38 machine-checked theorems prove
101//! the algebraic properties stated in the paper: Shamir reconstruction, Feldman VSS
102//! completeness, eVRF DH symmetry, refresh/reshare correctness, eVRF circuit
103//! completeness, security game hops, and the LHL bound. These are pure math proofs
104//! that hold in any field/group satisfying the standard algebraic axioms.
105//!
106//! **Bottom layer -- hax + F\* (Rust implementation):** The [`hax`](https://github.com/hacspec/hax)
107//! tool extracts the Rust source code into 18 F\* modules. F\* lax-checks all modules,
108//! verifying that the extracted code is well-typed against the arkworks type models.
109//! Non-crypto code (serialization, memory zeroization) is excluded via `#[hax_lib::exclude]`.
110//!
111//! **Bridge layer -- F\* specification files:** 6 F\* spec files state the correctness
112//! properties (mirroring the Lean theorems) and prove the extracted Rust code satisfies
113//! them. Key proofs include: eVRF pad symmetry (DH commutativity through the full
114//! `derive_pad` function), encrypt/decrypt roundtrip, Lagrange interpolation correctness
115//! for concrete cases (n=2,3), VSS ciphertext check (EC distributivity), and refresh/reshare
116//! algebraic invariants.
117//!
118//! Additionally, 20 [Kani](https://model-checking.github.io/kani/) bounded model checking
119//! harnesses prove panic-freedom and structural invariants across all modules.
120//!
121//! ### Remaining Items
122//!
123//! Two items are intentionally left unproved:
124//!
125//! - **`reshare_dealer_binding`** (F\*, `assume val`): States that if `g^a == g^b` then
126//!   `a == b`. This is the Discrete Logarithm hardness assumption -- a standard
127//!   cryptographic assumption that cannot be proved, only assumed.
128//!
129//! - **`golden_uc_security`** (Lean, `sorry`): The full UC composition theorem bounding
130//!   the distinguishing advantage as `|prob_real - prob_ideal| <= n * adv_evrf`. This
131//!   requires 8-12 weeks of research-level formalization using probabilistic frameworks
132//!   (VCV-io or SSProve). The statement is complete; the proof infrastructure is in place.
133//!
134//! ### Running the Verification Pipeline
135//!
136//! After any code change, run the full verification suite:
137//!
138//! ```bash
139//! # Full verification (cargo test + Lean + hax re-extraction + F* lax-check)
140//! make verify
141//!
142//! # Quick check (cargo test + Lean only, ~2 min)
143//! make verify-quick
144//!
145//! # Force full re-run (clears cached stamps)
146//! make -C formal_verification clean && make verify
147//! ```
148//!
149//! Prerequisites: Lean 4 via [elan](https://github.com/leanprover/elan), F\* v2025.10.06,
150//! hax v0.3.6 with `opam switch hax-engine`. See `formal_verification/README.md` for
151//! installation details.
152//!
153//! ## Paper Reference
154//!
155//! > Benedikt Bünz, Kevin Choi, Chelsea Komlo.
156//! > "Golden: Lightweight Non-Interactive Distributed Key Generation."
157//! > IACR ePrint 2025/1924.
158//! > <https://eprint.iacr.org/2025/1924>
159
160#![warn(missing_docs)]
161
162pub mod dkg;
163pub mod error;
164pub mod refresh;
165pub mod reshare;
166pub mod schnorr_pok;
167pub mod shamir;
168pub mod types;
169pub mod zk_evrf;
170
171// Internal modules (pub(crate) -- not part of public API)
172pub(crate) mod evrf;
173pub(crate) mod protocol;
174pub(crate) mod reshare_protocol;
175pub(crate) mod vss;
176
177// Feature-gated modules. These are NOT part of the DKG formal verification
178// target (hax extracts only the core DKG modules above). The threshold and
179// consensus modules have their own verification path.
180
181/// Threshold BLS signatures, vetKeys IBE, and drand-compatible beacon.
182/// Enabled by the `threshold` feature (on by default).
183#[cfg(feature = "threshold")]
184pub mod threshold;
185
186/// Simplex BFT consensus -- pure state machine core.
187/// Enabled by the `consensus` feature (on by default).
188#[cfg(feature = "consensus")]
189pub mod consensus;