Skip to content

Commit f1846ee

Browse files
committed
feat(protocol): implement From traits and add documentation
- feat: implement From traits for Protocol structure to enable type conversions - docs: add comprehensive description and documentation for Protocol structure
1 parent 67b1598 commit f1846ee

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/protocol.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
//! Implementation of a structure [`Protocol`] aimed at generalizing the SchnorrProtocol
2+
//! using the compositions of the latter via AND and OR links
3+
//!
4+
//! This structure allows, for example, the construction of protocols of the form:
5+
//! And(
6+
//! Or( dleq, pedersen_commitment ),
7+
//! Simple( discrete_logarithm ),
8+
//! And( pedersen_commitment_dleq, bbs_blind_commitment_computation )
9+
//! )
10+
111
use ff::{Field, PrimeField};
212
use group::{Group, GroupEncoding};
313

@@ -6,6 +16,7 @@ use crate::traits::CompactProtocol;
616
use crate::{
717
errors::Error,
818
fiat_shamir::{FiatShamir, HasGroupMorphism},
19+
group_morphism::GroupMorphismPreimage,
920
group_serialization::{deserialize_scalar, serialize_scalar},
1021
schnorr_protocol::SchnorrProtocol,
1122
traits::{SigmaProtocol, SigmaProtocolSimulator},
@@ -18,7 +29,23 @@ pub enum Protocol<G: Group + GroupEncoding> {
1829
Or(Vec<Protocol<G>>),
1930
}
2031

21-
/// Types associated
32+
impl<G> From<SchnorrProtocol<G>> for Protocol<G>
33+
where
34+
G: Group + GroupEncoding,
35+
{
36+
fn from(value: SchnorrProtocol<G>) -> Self {
37+
Protocol::Simple(value)
38+
}
39+
}
40+
41+
impl<G> From<GroupMorphismPreimage<G>> for Protocol<G>
42+
where
43+
G: Group + GroupEncoding,
44+
{
45+
fn from(value: GroupMorphismPreimage<G>) -> Self {
46+
Self::from(SchnorrProtocol::from(value))
47+
}
48+
}
2249

2350
#[derive(Clone)]
2451
pub enum ProtocolCommitment<G: Group + GroupEncoding> {

tests/composition_protocol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn composition_proof_correct() {
6868
let or_witness1 =
6969
sigma_rs::protocol::ProtocolWitness::Or(0, vec![ProtocolWitness::Simple(witness1)]);
7070

71-
let simple_protocol1 = Protocol::Simple(SchnorrProtocol::from(morph3));
71+
let simple_protocol1 = Protocol::from(morph3);
7272
let simple_witness1 = ProtocolWitness::Simple(witness3);
7373

7474
let and_protocol1 = Protocol::And(vec![

0 commit comments

Comments
 (0)