Skip to content

Commit 9e348fb

Browse files
committed
refactor: sigma_rs::group_morphism -> sigma_rs::linear_relation.
1 parent c4e101b commit 9e348fb

File tree

9 files changed

+114
-8
lines changed

9 files changed

+114
-8
lines changed

src/composition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::traits::CompactProtocol;
1616
use crate::{
1717
errors::Error,
1818
fiat_shamir::{FiatShamir, HasGroupMorphism},
19-
group_morphism::LinearRelation,
19+
linear_relation::LinearRelation,
2020
group_serialization::{deserialize_scalar, serialize_scalar},
2121
schnorr_protocol::SchnorrProtocol,
2222
traits::{SigmaProtocol, SigmaProtocolSimulator},

src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//! - Unimplemented methods.
1010
//! - Group element or scalar serialization failures.
1111
12-
use crate::group_morphism::GroupVar;
12+
use crate::linear_relation::GroupVar;
1313

1414
/// An error during proving or verification, such as a verification failure.
1515
#[non_exhaustive]

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
pub mod composition;
1616
pub mod errors;
1717
pub mod fiat_shamir;
18-
pub mod group_morphism;
18+
pub mod linear_relation;
1919
pub mod group_serialization;
2020
pub mod schnorr_protocol;
2121
pub mod traits;
@@ -24,3 +24,6 @@ pub mod codec;
2424

2525
#[cfg(test)]
2626
pub mod tests;
27+
28+
29+
pub use linear_relation::LinearRelation;

src/group_morphism.rs renamed to src/linear_relation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ where
339339
///
340340
/// # Example
341341
/// ```
342-
/// # use sigma_rs::group_morphism::LinearRelation;
342+
/// # use sigma_rs::LinearRelation;
343343
/// use curve25519_dalek::RistrettoPoint as G;
344344
///
345345
/// let mut morphism = LinearRelation::<G>::new();
@@ -367,7 +367,7 @@ where
367367
///
368368
/// # Example
369369
/// ```
370-
/// # use sigma_rs::group_morphism::LinearRelation;
370+
/// # use sigma_rs::LinearRelation;
371371
/// use curve25519_dalek::RistrettoPoint as G;
372372
///
373373
/// let mut morphism = LinearRelation::<G>::new();
File renamed without changes.

src/schnorr_protocol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use crate::codec::Codec;
88
use crate::errors::Error;
99
use crate::fiat_shamir::{FiatShamir, HasGroupMorphism};
10-
use crate::group_morphism::LinearRelation;
10+
use crate::linear_relation::LinearRelation;
1111
use crate::{
1212
group_serialization::*,
1313
traits::{CompactProtocol, SigmaProtocol, SigmaProtocolSimulator},

src/tests/composition_protocol.rs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
use curve25519_dalek::ristretto::RistrettoPoint;
2+
use group::Group;
3+
use rand::rngs::OsRng;
4+
5+
use super::test_utils::{
6+
bbs_blind_commitment_computation, discrete_logarithm, dleq, pedersen_commitment,
7+
pedersen_commitment_dleq,
8+
};
9+
use crate::codec::ShakeCodec;
10+
use crate::composition::{Protocol, ProtocolWitness};
11+
use crate::fiat_shamir::{HasGroupMorphism, NISigmaProtocol};
12+
use crate::schnorr_protocol::SchnorrProtocol;
13+
14+
type G = RistrettoPoint;
15+
16+
#[allow(non_snake_case)]
17+
#[test]
18+
fn composition_proof_correct() {
19+
// Composition and verification of proof for the following protocol :
20+
//
21+
// protocol = And(
22+
// Or( dleq, pedersen_commitment ),
23+
// Simple( discrete_logarithm ),
24+
// And( pedersen_commitment_dleq, bbs_blind_commitment_computation )
25+
// )
26+
let mut rng = OsRng;
27+
let domain_sep = b"hello world";
28+
29+
// definitions of the underlying protocols
30+
let (morph1, witness1) = dleq(<G as Group>::Scalar::random(&mut rng), G::random(&mut rng));
31+
let (morph2, _) = pedersen_commitment(
32+
G::random(&mut rng),
33+
<G as Group>::Scalar::random(&mut rng),
34+
<G as Group>::Scalar::random(&mut rng),
35+
);
36+
let (morph3, witness3) = discrete_logarithm(<G as Group>::Scalar::random(&mut rng));
37+
let (morph4, witness4) = pedersen_commitment_dleq(
38+
(0..4)
39+
.map(|_| G::random(&mut rng))
40+
.collect::<Vec<_>>()
41+
.try_into()
42+
.unwrap(),
43+
(0..2)
44+
.map(|_| <G as Group>::Scalar::random(&mut rng))
45+
.collect::<Vec<_>>()
46+
.try_into()
47+
.unwrap(),
48+
);
49+
let (morph5, witness5) = bbs_blind_commitment_computation(
50+
(0..4)
51+
.map(|_| G::random(&mut rng))
52+
.collect::<Vec<_>>()
53+
.try_into()
54+
.unwrap(),
55+
(0..3)
56+
.map(|_| <G as Group>::Scalar::random(&mut rng))
57+
.collect::<Vec<_>>()
58+
.try_into()
59+
.unwrap(),
60+
<G as Group>::Scalar::random(&mut rng),
61+
);
62+
63+
// second layer protocol definitions
64+
let or_protocol1 = Protocol::Or(vec![
65+
Protocol::Simple(SchnorrProtocol::from(morph1)),
66+
Protocol::Simple(SchnorrProtocol::from(morph2)),
67+
]);
68+
let or_witness1 = ProtocolWitness::Or(0, vec![ProtocolWitness::Simple(witness1)]);
69+
70+
let simple_protocol1 = Protocol::from(morph3);
71+
let simple_witness1 = ProtocolWitness::Simple(witness3);
72+
73+
let and_protocol1 = Protocol::And(vec![
74+
Protocol::Simple(SchnorrProtocol::from(morph4)),
75+
Protocol::Simple(SchnorrProtocol::from(morph5)),
76+
]);
77+
let and_witness1 = ProtocolWitness::And(vec![
78+
ProtocolWitness::Simple(witness4),
79+
ProtocolWitness::Simple(witness5),
80+
]);
81+
82+
// definition of the final protocol
83+
let protocol = Protocol::And(vec![or_protocol1, simple_protocol1, and_protocol1]);
84+
let witness = ProtocolWitness::And(vec![or_witness1, simple_witness1, and_witness1]);
85+
86+
let mut nizk =
87+
NISigmaProtocol::<Protocol<RistrettoPoint>, ShakeCodec<G>>::new(domain_sep, protocol);
88+
89+
nizk.sigmap
90+
.absorb_morphism_structure(&mut nizk.hash_state)
91+
.unwrap();
92+
93+
// Batchable and compact proofs
94+
let proof_batchable_bytes = nizk.prove_batchable(&witness, &mut rng).unwrap();
95+
let proof_compact_bytes = nizk.prove_compact(&witness, &mut rng).unwrap();
96+
// Verify proofs
97+
let verified_batchable = nizk.verify_batchable(&proof_batchable_bytes).is_ok();
98+
let verified_compact = nizk.verify_compact(&proof_compact_bytes).is_ok();
99+
assert!(
100+
verified_batchable & verified_compact,
101+
"Fiat-Shamir Schnorr proof verification failed"
102+
);
103+
}

src/tests/spec/custom_schnorr_protocol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rand::{CryptoRng, Rng};
55
use crate::codec::Codec;
66
use crate::errors::Error;
77
use crate::fiat_shamir::FiatShamir;
8-
use crate::group_morphism::LinearRelation;
8+
use crate::linear_relation::LinearRelation;
99
use crate::group_serialization::*;
1010
use crate::tests::spec::random::SRandom;
1111
use crate::traits::SigmaProtocol;

src/tests/test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use group::{Group, GroupEncoding};
44

5-
use crate::group_morphism::{LinearRelation, msm_pr};
5+
use crate::linear_relation::{LinearRelation, msm_pr};
66

77
/// Morphism for knowledge of a discrete logarithm relative to a fixed basepoint.
88
#[allow(non_snake_case)]

0 commit comments

Comments
 (0)