Skip to content

Commit efd6de6

Browse files
committed
refactor(proof-builder): migrate to new Protocol structure and add documentation
- refactor: update proof_builder to use the new generalized Protocol structure - docs: add comprehensive documentation for updated proof_builder functionality
1 parent f1846ee commit efd6de6

File tree

4 files changed

+40
-8
lines changed

4 files changed

+40
-8
lines changed

src/fiat_shamir.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,25 @@ use crate::traits::{CompactProtocol, SigmaProtocol};
1818

1919
use rand::{CryptoRng, RngCore};
2020

21+
/// A trait that allows sigma protocols to have a Fiat-Shamir transform to have a
22+
/// deterministic challenge generation function.
23+
///
24+
/// Challenge generation occurs in two stages:
25+
/// - `push_commitment`: absorbs commitments to feed the codec
26+
/// - `get_challenge`: extracts the challenge from the codec
27+
///
28+
/// # Type Parameters
29+
/// - `C`: the codec used for the underlying determenitis function.
2130
pub trait FiatShamir<C: Codec>: SigmaProtocol {
2231
fn push_commitment(&self, codec: &mut C, commitment: &Self::Commitment);
2332

2433
fn get_challenge(&self, codec: &mut C) -> Result<Self::Challenge, Error>;
2534
}
2635

27-
/// Trait for accessing the underlying group morphism in a Sigma protocol.
36+
/// Structures implementing this trait must implicitly have one or more underlying [`GroupMorphism`] elements.
37+
///
38+
/// This trait allows the data of the morphisms underlying the structure to be absorbed into a codec.
2839
pub trait HasGroupMorphism {
29-
/// Absorbs the morphism structure into a codec.
30-
/// Only compatible with 64-bit platforms
3140
fn absorb_morphism_structure<C: Codec>(&self, codec: &mut C) -> Result<(), Error>;
3241
}
3342

@@ -60,7 +69,6 @@ where
6069
pub sigmap: P,
6170
}
6271

63-
// TODO: Write a serialization of the morphism to the transcript.
6472
impl<P, C> NISigmaProtocol<P, C>
6573
where
6674
P: SigmaProtocol<Challenge: PartialEq> + FiatShamir<C>,

src/proof_builder.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@
1111
//! - Allocates scalar and point variables for constructing group equations.
1212
//! - Appends equations representing statements to be proven.
1313
//! - Supports element assignment to statement variables.
14+
//! - Composes multiple protocols via AND and OR connections
1415
//! - Offers one-shot `prove` and `verify` methods.
1516
16-
use crate::{codec::ShakeCodec, fiat_shamir::NISigmaProtocol, schnorr_protocol::SchnorrProtocol};
17+
use crate::{codec::ShakeCodec, fiat_shamir::NISigmaProtocol, protocol::Protocol};
1718

18-
/// An alias for a [`SchnorrProtocol`] over a [`GroupMorphismPreimage`] and applies
19+
/// An alias for a [`Protocol`] on [`GroupMorphismPreimage`] and applies
1920
/// the Fiat-Shamir transform via [`NISigmaProtocol`].
2021
///
2122
/// # Type Parameters
2223
/// - `G`: A group that implements both [`Group`] and [`GroupEncoding`].
2324
///
2425
/// [`GroupMorphismPreimage`]: crate::GroupMorphismPreimage
25-
pub type NISchnorr<G> = NISigmaProtocol<SchnorrProtocol<G>, ShakeCodec<G>>;
26+
pub type NIProtocol<G> = NISigmaProtocol<Protocol<G>, ShakeCodec<G>>;

src/protocol.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Implementation of a structure [`Protocol`] aimed at generalizing the SchnorrProtocol
1+
//! Implementation of a structure [`Protocol`] aimed at generalizing the SchnorrProtocol
22
//! using the compositions of the latter via AND and OR links
33
//!
44
//! This structure allows, for example, the construction of protocols of the form:
@@ -22,6 +22,12 @@ use crate::{
2222
traits::{SigmaProtocol, SigmaProtocolSimulator},
2323
};
2424

25+
/// A protocol proving knowledge of a witness for a composition of SchnorrProtocol's.
26+
///
27+
/// This implementation generalizes [`SchnorrProtocol`] by using AND/OR links.
28+
///
29+
/// # Type Parameters
30+
/// - `G`: A cryptographic group implementing [`Group`] and [`GroupEncoding`].
2531
#[derive(Clone)]
2632
pub enum Protocol<G: Group + GroupEncoding> {
2733
Simple(SchnorrProtocol<G>),
@@ -47,13 +53,15 @@ where
4753
}
4854
}
4955

56+
// Structure representing the Commitment type of Protocol as SigmaProtocol
5057
#[derive(Clone)]
5158
pub enum ProtocolCommitment<G: Group + GroupEncoding> {
5259
Simple(<SchnorrProtocol<G> as SigmaProtocol>::Commitment),
5360
And(Vec<ProtocolCommitment<G>>),
5461
Or(Vec<ProtocolCommitment<G>>),
5562
}
5663

64+
// Structure representing the ProverState type of Protocol as SigmaProtocol
5765
#[derive(Clone)]
5866
pub enum ProtocolProverState<G: Group + GroupEncoding> {
5967
Simple(<SchnorrProtocol<G> as SigmaProtocol>::ProverState),
@@ -65,19 +73,22 @@ pub enum ProtocolProverState<G: Group + GroupEncoding> {
6573
),
6674
}
6775

76+
// Structure representing the Response type of Protocol as SigmaProtocol
6877
#[derive(Clone)]
6978
pub enum ProtocolResponse<G: Group + GroupEncoding> {
7079
Simple(<SchnorrProtocol<G> as SigmaProtocol>::Response),
7180
And(Vec<ProtocolResponse<G>>),
7281
Or(Vec<ProtocolChallenge<G>>, Vec<ProtocolResponse<G>>),
7382
}
7483

84+
// Structure representing the Witness type of Protocol as SigmaProtocol
7585
pub enum ProtocolWitness<G: Group + GroupEncoding> {
7686
Simple(<SchnorrProtocol<G> as SigmaProtocol>::Witness),
7787
And(Vec<ProtocolWitness<G>>),
7888
Or(usize, Vec<ProtocolWitness<G>>),
7989
}
8090

91+
// Structure representing the Challenge type of Protocol as SigmaProtocol
8192
type ProtocolChallenge<G> = <SchnorrProtocol<G> as SigmaProtocol>::Challenge;
8293

8394
impl<G: Group + GroupEncoding> SigmaProtocol for Protocol<G> {

src/schnorr_protocol.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,11 @@ where
417417
C: Codec<Challenge = <G as Group>::Scalar>,
418418
G: Group + GroupEncoding,
419419
{
420+
/// Absorbs commitments into the codec for future use of the codec
421+
///
422+
/// # Parameters
423+
/// - `codec`: the Codec that absorbs commitments
424+
/// - `commitment`: a commitment of SchnorrProtocol
420425
fn push_commitment(&self, codec: &mut C, commitment: &Self::Commitment) {
421426
let mut data = Vec::new();
422427
for commit in commitment {
@@ -425,6 +430,13 @@ where
425430
codec.prover_message(&data);
426431
}
427432

433+
/// Generates a challenge from the codec that absorbed the commitments
434+
///
435+
/// # Parameters
436+
/// - `codec`: the Codec from which the challenge is generated
437+
///
438+
/// # Returns
439+
/// - A `challenge`` that can be used during a non-interactive protocol
428440
fn get_challenge(&self, codec: &mut C) -> Result<Self::Challenge, Error> {
429441
Ok(codec.verifier_challenge())
430442
}

0 commit comments

Comments
 (0)