Skip to content

Commit 86a75bc

Browse files
ChausseaumoineGOURIOU Lénaïck
andauthored
refactor: naming consistent with specification. (#29)
Co-authored-by: GOURIOU Lénaïck <[email protected]>
1 parent 5df9512 commit 86a75bc

File tree

8 files changed

+59
-58
lines changed

8 files changed

+59
-58
lines changed

examples/schnorr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use rand::rngs::OsRng;
3939
use sigma_rs::codec::ShakeCodec;
4040
use sigma_rs::fiat_shamir::NISigmaProtocol;
4141
use sigma_rs::linear_relation::LinearRelation;
42-
use sigma_rs::schnorr_protocol::SchnorrProtocol;
42+
use sigma_rs::schnorr_protocol::SchnorrProof;
4343

4444
/// Construct the relation `P = x·G` and return it along with the witness `x`:
4545
/// - `x` is an element from a group of prime order $p$, typically $\mathbb{Z}_p$,
@@ -69,7 +69,7 @@ pub fn discrete_logarithm<G: Group + GroupEncoding>(
6969
// Since the witness is provided to the function, we only need to assign the group points.
7070

7171
// Assign the group generator to the corresponding variable `G`
72-
morphism.assign_element(var_G, G::generator());
72+
morphism.set_element(var_G, G::generator());
7373

7474
// Assign the value of the image to the variable `P` (i.e., evaluate the group equation for `x`)
7575
morphism.compute_image(&[x]).unwrap();
@@ -94,7 +94,7 @@ fn main() {
9494
let (relation, witness) = discrete_logarithm(x);
9595

9696
// Build the Sigma protocol instance from the relation.
97-
let schnorr = SchnorrProtocol::<RistrettoPoint>::from(relation);
97+
let schnorr = SchnorrProof::<RistrettoPoint>::from(relation);
9898

9999
// Convert the Sigma protocol instance to a non-interactive protocol via Fiat-Shamir.
100100
// A domain separator is given as a byte-sequence to identify the current instance being proven.

examples/simple_composition.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub fn discrete_logarithm<G: Group + GroupEncoding>(
7575
let var_X = morphism.allocate_eq(var_x * var_G);
7676

7777
// Assign concrete values
78-
morphism.assign_element(var_G, G::generator());
78+
morphism.set_element(var_G, G::generator());
7979
morphism.compute_image(&[x]).unwrap();
8080

8181
// Verify: X = x * G
@@ -102,7 +102,7 @@ pub fn dleq<G: Group + GroupEncoding>(x: G::Scalar, H: G) -> (LinearRelation<G>,
102102
let _var_Y = morphism.allocate_eq(var_x * var_H);
103103

104104
// Assign concrete values
105-
morphism.assign_elements([(var_G, G::generator()), (var_H, H)]);
105+
morphism.set_elements([(var_G, G::generator()), (var_H, H)]);
106106
morphism.compute_image(&[x]).unwrap();
107107

108108
// Verify: X = x * G and Y = x * H

src/composition.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//! Implementation of a structure [`Protocol`] aimed at generalizing the [`SchnorrProtocol`] using the compositions of the latter via AND and OR links.
1+
//! Implementation of a structure [`Protocol`] aimed at generalizing the [`SchnorrProof`]
2+
//! using the compositions of the latter via AND and OR links
23
//!
34
//! This structure allows, for example, the construction of protocols of the form:
45
//! And(
@@ -17,28 +18,28 @@ use crate::{
1718
fiat_shamir::FiatShamir,
1819
group_serialization::{deserialize_scalar, serialize_scalar},
1920
linear_relation::LinearRelation,
20-
schnorr_protocol::SchnorrProtocol,
21+
schnorr_protocol::SchnorrProof,
2122
traits::{SigmaProtocol, SigmaProtocolSimulator},
2223
};
2324

24-
/// A protocol proving knowledge of a witness for a composition of SchnorrProtocol's.
25+
/// A protocol proving knowledge of a witness for a composition of SchnorrProof's.
2526
///
26-
/// This implementation generalizes [`SchnorrProtocol`] by using AND/OR links.
27+
/// This implementation generalizes [`SchnorrProof`] by using AND/OR links.
2728
///
2829
/// # Type Parameters
2930
/// - `G`: A cryptographic group implementing [`Group`] and [`GroupEncoding`].
3031
#[derive(Clone)]
3132
pub enum Protocol<G: Group + GroupEncoding> {
32-
Simple(SchnorrProtocol<G>),
33+
Simple(SchnorrProof<G>),
3334
And(Vec<Protocol<G>>),
3435
Or(Vec<Protocol<G>>),
3536
}
3637

37-
impl<G> From<SchnorrProtocol<G>> for Protocol<G>
38+
impl<G> From<SchnorrProof<G>> for Protocol<G>
3839
where
3940
G: Group + GroupEncoding,
4041
{
41-
fn from(value: SchnorrProtocol<G>) -> Self {
42+
fn from(value: SchnorrProof<G>) -> Self {
4243
Protocol::Simple(value)
4344
}
4445
}
@@ -48,22 +49,22 @@ where
4849
G: Group + GroupEncoding,
4950
{
5051
fn from(value: LinearRelation<G>) -> Self {
51-
Self::from(SchnorrProtocol::from(value))
52+
Self::from(SchnorrProof::from(value))
5253
}
5354
}
5455

5556
// Structure representing the Commitment type of Protocol as SigmaProtocol
5657
#[derive(Clone)]
5758
pub enum ProtocolCommitment<G: Group + GroupEncoding> {
58-
Simple(<SchnorrProtocol<G> as SigmaProtocol>::Commitment),
59+
Simple(<SchnorrProof<G> as SigmaProtocol>::Commitment),
5960
And(Vec<ProtocolCommitment<G>>),
6061
Or(Vec<ProtocolCommitment<G>>),
6162
}
6263

6364
// Structure representing the ProverState type of Protocol as SigmaProtocol
6465
#[derive(Clone)]
6566
pub enum ProtocolProverState<G: Group + GroupEncoding> {
66-
Simple(<SchnorrProtocol<G> as SigmaProtocol>::ProverState),
67+
Simple(<SchnorrProof<G> as SigmaProtocol>::ProverState),
6768
And(Vec<ProtocolProverState<G>>),
6869
Or(
6970
usize, // real index
@@ -75,20 +76,20 @@ pub enum ProtocolProverState<G: Group + GroupEncoding> {
7576
// Structure representing the Response type of Protocol as SigmaProtocol
7677
#[derive(Clone)]
7778
pub enum ProtocolResponse<G: Group + GroupEncoding> {
78-
Simple(<SchnorrProtocol<G> as SigmaProtocol>::Response),
79+
Simple(<SchnorrProof<G> as SigmaProtocol>::Response),
7980
And(Vec<ProtocolResponse<G>>),
8081
Or(Vec<ProtocolChallenge<G>>, Vec<ProtocolResponse<G>>),
8182
}
8283

8384
// Structure representing the Witness type of Protocol as SigmaProtocol
8485
pub enum ProtocolWitness<G: Group + GroupEncoding> {
85-
Simple(<SchnorrProtocol<G> as SigmaProtocol>::Witness),
86+
Simple(<SchnorrProof<G> as SigmaProtocol>::Witness),
8687
And(Vec<ProtocolWitness<G>>),
8788
Or(usize, Vec<ProtocolWitness<G>>),
8889
}
8990

9091
// Structure representing the Challenge type of Protocol as SigmaProtocol
91-
type ProtocolChallenge<G> = <SchnorrProtocol<G> as SigmaProtocol>::Challenge;
92+
type ProtocolChallenge<G> = <SchnorrProof<G> as SigmaProtocol>::Challenge;
9293

9394
impl<G: Group + GroupEncoding> SigmaProtocol for Protocol<G> {
9495
type Commitment = ProtocolCommitment<G>;

src/linear_relation.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ where
316316
/// # Parameters
317317
/// - `lhs`: The image group element variable (left-hand side of the equation).
318318
/// - `rhs`: A slice of `(ScalarVar, GroupVar)` pairs representing the linear combination on the right-hand side.
319-
pub fn constrain(&mut self, lhs: GroupVar, rhs: impl Into<LinearCombination>) {
319+
pub fn append_equation(&mut self, lhs: GroupVar, rhs: impl Into<LinearCombination>) {
320320
self.morphism.append(rhs.into());
321321
self.image.push(lhs);
322322
}
@@ -329,7 +329,7 @@ where
329329
/// - `rhs`: A slice of `(ScalarVar, GroupVar)` pairs representing the linear combination on the right-hand side.
330330
pub fn allocate_eq(&mut self, rhs: impl Into<LinearCombination>) -> GroupVar {
331331
let var = self.allocate_element();
332-
self.constrain(var, rhs);
332+
self.append_equation(var, rhs);
333333
var
334334
}
335335

@@ -399,7 +399,7 @@ where
399399
/// # Panics
400400
///
401401
/// Panics if the given assignment conflicts with the existing assignment.
402-
pub fn assign_element(&mut self, var: GroupVar, element: G) {
402+
pub fn set_element(&mut self, var: GroupVar, element: G) {
403403
self.morphism.group_elements.assign_element(var, element)
404404
}
405405

@@ -412,7 +412,7 @@ where
412412
/// # Panics
413413
///
414414
/// Panics if the collection contains two conflicting assignments for the same variable.
415-
pub fn assign_elements(&mut self, assignments: impl IntoIterator<Item = (GroupVar, G)>) {
415+
pub fn set_elements(&mut self, assignments: impl IntoIterator<Item = (GroupVar, G)>) {
416416
self.morphism.group_elements.assign_elements(assignments)
417417
}
418418

src/schnorr_protocol.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Implementation of the generic Schnorr Sigma Protocol over a group `G`.
22
//!
3-
//! This module defines the [`SchnorrProtocol`] structure, which implements
3+
//! This module defines the [`SchnorrProof`] structure, which implements
44
//! a Sigma protocol proving different types of discrete logarithm relations (eg. Schnorr, Pedersen's commitments)
55
//! through a group morphism abstraction (see Maurer09).
66
@@ -25,9 +25,9 @@ use rand::{CryptoRng, RngCore};
2525
/// # Type Parameters
2626
/// - `G`: A cryptographic group implementing [`Group`] and [`GroupEncoding`].
2727
#[derive(Clone, Default, Debug)]
28-
pub struct SchnorrProtocol<G: Group + GroupEncoding>(pub LinearRelation<G>);
28+
pub struct SchnorrProof<G: Group + GroupEncoding>(pub LinearRelation<G>);
2929

30-
impl<G: Group + GroupEncoding> SchnorrProtocol<G> {
30+
impl<G: Group + GroupEncoding> SchnorrProof<G> {
3131
pub fn scalars_nb(&self) -> usize {
3232
self.0.morphism.num_scalars
3333
}
@@ -37,7 +37,7 @@ impl<G: Group + GroupEncoding> SchnorrProtocol<G> {
3737
}
3838
}
3939

40-
impl<G> From<LinearRelation<G>> for SchnorrProtocol<G>
40+
impl<G> From<LinearRelation<G>> for SchnorrProof<G>
4141
where
4242
G: Group + GroupEncoding,
4343
{
@@ -46,7 +46,7 @@ where
4646
}
4747
}
4848

49-
impl<G> SigmaProtocol for SchnorrProtocol<G>
49+
impl<G> SigmaProtocol for SchnorrProof<G>
5050
where
5151
G: Group + GroupEncoding,
5252
{
@@ -246,7 +246,7 @@ where
246246
}
247247
}
248248

249-
impl<G> CompactProtocol for SchnorrProtocol<G>
249+
impl<G> CompactProtocol for SchnorrProof<G>
250250
where
251251
G: Group + GroupEncoding,
252252
{
@@ -389,7 +389,7 @@ where
389389
}
390390
}
391391

392-
impl<G> SigmaProtocolSimulator for SchnorrProtocol<G>
392+
impl<G> SigmaProtocolSimulator for SchnorrProof<G>
393393
where
394394
G: Group + GroupEncoding,
395395
{
@@ -430,7 +430,7 @@ where
430430
}
431431
}
432432

433-
impl<G, C> FiatShamir<C> for SchnorrProtocol<G>
433+
impl<G, C> FiatShamir<C> for SchnorrProof<G>
434434
where
435435
C: Codec<Challenge = <G as Group>::Scalar>,
436436
G: Group + GroupEncoding,
@@ -439,9 +439,9 @@ where
439439
///
440440
/// # Parameters
441441
/// - `codec`: the Codec that absorbs commitments
442-
/// - `commitment`: a commitment of SchnorrProtocol
442+
/// - `commitment`: a commitment of [`SchnorrProof`].
443443
fn absorb_commitment(&self, codec: &mut C, commitment: &Self::Commitment) {
444-
let mut data = Vec::new();
444+
let mut data = self.0.label();
445445
for commit in commitment {
446446
data.extend_from_slice(commit.to_bytes().as_ref());
447447
}

src/tests/composition.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use super::test_utils::{
99
use crate::codec::ShakeCodec;
1010
use crate::composition::{Protocol, ProtocolWitness};
1111
use crate::fiat_shamir::NISigmaProtocol;
12-
use crate::schnorr_protocol::SchnorrProtocol;
12+
use crate::schnorr_protocol::SchnorrProof;
1313

1414
type G = RistrettoPoint;
1515

@@ -62,17 +62,17 @@ fn composition_proof_correct() {
6262

6363
// second layer protocol definitions
6464
let or_protocol1 = Protocol::Or(vec![
65-
Protocol::Simple(SchnorrProtocol::from(morph1)),
66-
Protocol::Simple(SchnorrProtocol::from(morph2)),
65+
Protocol::Simple(SchnorrProof::from(morph1)),
66+
Protocol::Simple(SchnorrProof::from(morph2)),
6767
]);
6868
let or_witness1 = ProtocolWitness::Or(0, vec![ProtocolWitness::Simple(witness1)]);
6969

7070
let simple_protocol1 = Protocol::from(morph3);
7171
let simple_witness1 = ProtocolWitness::Simple(witness3);
7272

7373
let and_protocol1 = Protocol::And(vec![
74-
Protocol::Simple(SchnorrProtocol::from(morph4)),
75-
Protocol::Simple(SchnorrProtocol::from(morph5)),
74+
Protocol::Simple(SchnorrProof::from(morph4)),
75+
Protocol::Simple(SchnorrProof::from(morph5)),
7676
]);
7777
let and_witness1 = ProtocolWitness::And(vec![
7878
ProtocolWitness::Simple(witness4),

src/tests/relations.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::tests::test_utils::{
77
bbs_blind_commitment_computation, discrete_logarithm, dleq, pedersen_commitment,
88
pedersen_commitment_dleq,
99
};
10-
use crate::{codec::ShakeCodec, schnorr_protocol::SchnorrProtocol};
10+
use crate::{codec::ShakeCodec, schnorr_protocol::SchnorrProof};
1111

1212
/// This part tests the functioning of morphisms
1313
/// as well as the implementation of LinearRelation
@@ -69,17 +69,17 @@ fn test_bbs_blind_commitment_computation() {
6969
}
7070

7171
/// This part tests the implementation of the SigmaProtocol trait for the
72-
/// SchnorrProtocol structure as well as the Fiat-Shamir NISigmaProtocol transform
72+
/// SchnorrProof structure as well as the Fiat-Shamir NISigmaProtocol transform
7373
#[test]
7474
fn noninteractive_discrete_logarithm() {
7575
let mut rng = OsRng;
7676
let (morphismp, witness) = discrete_logarithm(Scalar::random(&mut rng));
7777

7878
// The SigmaProtocol induced by morphismp
79-
let protocol = SchnorrProtocol::from(morphismp);
79+
let protocol = SchnorrProof::from(morphismp);
8080
// Fiat-Shamir wrapper
8181
let domain_sep = b"test-fiat-shamir-schnorr";
82-
let nizk = NISigmaProtocol::<SchnorrProtocol<G>, ShakeCodec<G>>::new(domain_sep, protocol);
82+
let nizk = NISigmaProtocol::<SchnorrProof<G>, ShakeCodec<G>>::new(domain_sep, protocol);
8383

8484
// Batchable and compact proofs
8585
let proof_batchable_bytes = nizk.prove_batchable(&witness, &mut rng).unwrap();
@@ -103,10 +103,10 @@ fn noninteractive_dleq() {
103103
let (morphismp, witness) = dleq(Scalar::random(&mut rng), G::random(&mut rng));
104104

105105
// The SigmaProtocol induced by morphismp
106-
let protocol = SchnorrProtocol::from(morphismp);
106+
let protocol = SchnorrProof::from(morphismp);
107107
// Fiat-Shamir wrapper
108108
let domain_sep = b"test-fiat-shamir-DLEQ";
109-
let nizk = NISigmaProtocol::<SchnorrProtocol<G>, ShakeCodec<G>>::new(domain_sep, protocol);
109+
let nizk = NISigmaProtocol::<SchnorrProof<G>, ShakeCodec<G>>::new(domain_sep, protocol);
110110

111111
// Batchable and compact proofs
112112
let proof_batchable_bytes = nizk.prove_batchable(&witness, &mut rng).unwrap();
@@ -134,10 +134,10 @@ fn noninteractive_pedersen_commitment() {
134134
);
135135

136136
// The SigmaProtocol induced by morphismp
137-
let protocol = SchnorrProtocol::from(morphismp);
137+
let protocol = SchnorrProof::from(morphismp);
138138
// Fiat-Shamir wrapper
139139
let domain_sep = b"test-fiat-shamir-pedersen-commitment";
140-
let nizk = NISigmaProtocol::<SchnorrProtocol<G>, ShakeCodec<G>>::new(domain_sep, protocol);
140+
let nizk = NISigmaProtocol::<SchnorrProof<G>, ShakeCodec<G>>::new(domain_sep, protocol);
141141

142142
// Batchable and compact proofs
143143
let proof_batchable_bytes = nizk.prove_batchable(&witness, &mut rng).unwrap();
@@ -172,10 +172,10 @@ fn noninteractive_pedersen_commitment_dleq() {
172172
);
173173

174174
// The SigmaProtocol induced by morphismp
175-
let protocol = SchnorrProtocol::from(morphismp);
175+
let protocol = SchnorrProof::from(morphismp);
176176
// Fiat-Shamir wrapper
177177
let domain_sep = b"test-fiat-shamir-pedersen-commitment-DLEQ";
178-
let nizk = NISigmaProtocol::<SchnorrProtocol<G>, ShakeCodec<G>>::new(domain_sep, protocol);
178+
let nizk = NISigmaProtocol::<SchnorrProof<G>, ShakeCodec<G>>::new(domain_sep, protocol);
179179

180180
// Batchable and compact proofs
181181
let proof_batchable_bytes = nizk.prove_batchable(&witness, &mut rng).unwrap();
@@ -211,10 +211,10 @@ fn noninteractive_bbs_blind_commitment_computation() {
211211
);
212212

213213
// The SigmaProtocol induced by morphismp
214-
let protocol = SchnorrProtocol::from(morphismp);
214+
let protocol = SchnorrProof::from(morphismp);
215215
// Fiat-Shamir wrapper
216216
let domain_sep = b"test-fiat-shamir-bbs-blind-commitment-computation";
217-
let nizk = NISigmaProtocol::<SchnorrProtocol<G>, ShakeCodec<G>>::new(domain_sep, protocol);
217+
let nizk = NISigmaProtocol::<SchnorrProof<G>, ShakeCodec<G>>::new(domain_sep, protocol);
218218

219219
// Batchable and compact proofs
220220
let proof_batchable_bytes = nizk.prove_batchable(&witness, &mut rng).unwrap();

0 commit comments

Comments
 (0)