Skip to content

Commit 00d57a9

Browse files
committed
Updated morphism to linear map naming
1 parent 9e1e903 commit 00d57a9

File tree

4 files changed

+72
-73
lines changed

4 files changed

+72
-73
lines changed

src/linear_relation/mod.rs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
//! # Linear Maps and Relations Handling.
22
//!
3-
//! This module provides utilities for describing and manipulating **linear group morphisms**,
3+
//! This module provides utilities for describing and manipulating **linear group linear maps**,
44
//! supporting sigma protocols over group-based statements (e.g., discrete logarithms, DLEQ proofs). See Maurer09.
55
//!
66
//! It includes:
77
//! - [`LinearCombination`]: a sparse representation of scalar multiplication relations.
88
//! - [`LinearMap`]: a collection of linear combinations acting on group elements.
9-
//! - [`LinearRelation`]: a higher-level structure managing morphisms and their associated images.
9+
//! - [`LinearRelation`]: a higher-level structure managing linear maps and their associated images.
1010
1111
use std::collections::BTreeMap;
1212
use std::iter;
@@ -245,8 +245,7 @@ impl<G: Group> FromIterator<(GroupVar<G>, G)> for GroupMap<G> {
245245
pub struct LinearMap<G: Group> {
246246
/// The set of linear combination constraints (equations).
247247
pub constraints: Vec<LinearCombination<G>>,
248-
// TODO: Update the usage of the word "morphism"
249-
/// The list of group elements referenced in the morphism.
248+
/// The list of group elements referenced in the linear map.
250249
///
251250
/// Uninitialized group elements are presented with `None`.
252251
pub group_elements: GroupMap<G>,
@@ -296,15 +295,15 @@ impl<G: Group> LinearMap<G> {
296295
self.constraints.len()
297296
}
298297

299-
/// Adds a new linear combination constraint to the morphism.
298+
/// Adds a new linear combination constraint to the linear map.
300299
///
301300
/// # Parameters
302301
/// - `lc`: The [`LinearCombination`] to add.
303302
pub fn append(&mut self, lc: LinearCombination<G>) {
304303
self.constraints.push(lc);
305304
}
306305

307-
/// Evaluates all linear combinations in the morphism with the provided scalars.
306+
/// Evaluates all linear combinations in the linear map with the provided scalars.
308307
///
309308
/// # Parameters
310309
/// - `scalars`: A slice of scalar values corresponding to the scalar variables.
@@ -334,8 +333,8 @@ impl<G: Group> LinearMap<G> {
334333

335334
/// A wrapper struct coupling a [`LinearMap`] with the corresponding expected output (image) elements.
336335
///
337-
/// This structure represents the *preimage problem* for a group morphism: given a set of scalar inputs,
338-
/// determine whether their image under the morphism matches a target set of group elements.
336+
/// This structure represents the *preimage problem* for a group linear map: given a set of scalar inputs,
337+
/// determine whether their image under the linear map matches a target set of group elements.
339338
///
340339
/// Internally, the constraint system is defined through:
341340
/// - A list of group elements and linear equations (held in the [`LinearMap`] field),
@@ -391,7 +390,7 @@ where
391390
var
392391
}
393392

394-
/// Allocates a scalar variable for use in the morphism.
393+
/// Allocates a scalar variable for use in the linear map.
395394
pub fn allocate_scalar(&mut self) -> ScalarVar<G> {
396395
self.linear_map.num_scalars += 1;
397396
ScalarVar(self.linear_map.num_scalars - 1, PhantomData)
@@ -407,9 +406,9 @@ where
407406
/// # use sigma_rs::LinearRelation;
408407
/// use curve25519_dalek::RistrettoPoint as G;
409408
///
410-
/// let mut morphism = LinearRelation::<G>::new();
411-
/// let [var_x, var_y] = morphism.allocate_scalars();
412-
/// let vars = morphism.allocate_scalars::<10>();
409+
/// let mut linear map = LinearRelation::<G>::new();
410+
/// let [var_x, var_y] = linear map.allocate_scalars();
411+
/// let vars = linear map.allocate_scalars::<10>();
413412
/// ```
414413
pub fn allocate_scalars<const N: usize>(&mut self) -> [ScalarVar<G>; N] {
415414
let mut vars = [ScalarVar(usize::MAX, PhantomData); N];
@@ -419,13 +418,13 @@ where
419418
vars
420419
}
421420

422-
/// Allocates a point variable (group element) for use in the morphism.
421+
/// Allocates a point variable (group element) for use in the linear map.
423422
pub fn allocate_element(&mut self) -> GroupVar<G> {
424423
self.linear_map.num_elements += 1;
425424
GroupVar(self.linear_map.num_elements - 1, PhantomData)
426425
}
427426

428-
/// Allocates `N` point variables (group elements) for use in the morphism.
427+
/// Allocates `N` point variables (group elements) for use in the linear map.
429428
///
430429
/// # Returns
431430
/// An array of [`GroupVar`] representing the newly allocated group element indices.
@@ -435,9 +434,9 @@ where
435434
/// # use sigma_rs::LinearRelation;
436435
/// use curve25519_dalek::RistrettoPoint as G;
437436
///
438-
/// let mut morphism = LinearRelation::<G>::new();
439-
/// let [var_g, var_h] = morphism.allocate_elements();
440-
/// let vars = morphism.allocate_elements::<10>();
437+
/// let mut linear map = LinearRelation::<G>::new();
438+
/// let [var_g, var_h] = linear map.allocate_elements();
439+
/// let vars = linear map.allocate_elements::<10>();
441440
/// ```
442441
pub fn allocate_elements<const N: usize>(&mut self) -> [GroupVar<G>; N] {
443442
let mut vars = [GroupVar(usize::MAX, PhantomData); N];
@@ -474,7 +473,7 @@ where
474473
self.linear_map.group_elements.assign_elements(assignments)
475474
}
476475

477-
/// Evaluates all linear combinations in the morphism with the provided scalars, computing the
476+
/// Evaluates all linear combinations in the linear map with the provided scalars, computing the
478477
/// left-hand side of this constraints (i.e. the image).
479478
///
480479
/// After calling this function, all point variables will be assigned.
@@ -519,7 +518,7 @@ where
519518
///
520519
/// # Returns
521520
///
522-
/// A vector of group elements (`Vec<G>`) representing the morphism's image.
521+
/// A vector of group elements (`Vec<G>`) representing the linear map's image.
523522
// TODO: Should this return GroupMap?
524523
pub fn image(&self) -> Result<Vec<G>, Error> {
525524
self.image
@@ -528,7 +527,7 @@ where
528527
.collect()
529528
}
530529

531-
/// Returns a binary label describing the morphism.
530+
/// Returns a binary label describing the linear map.
532531
///
533532
/// The format is:
534533
/// - [Ne: u32] number of equations

src/schnorr_protocol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ where
5959
/// Prover's first message: generates a commitment using random nonces.
6060
///
6161
/// # Parameters
62-
/// - `witness`: A vector of scalars that satisfy the morphism relation.
62+
/// - `witness`: A vector of scalars that satisfy the linear map relation.
6363
/// - `rng`: A cryptographically secure random number generator.
6464
///
6565
/// # Returns

src/tests/relations.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::tests::test_utils::{
99
};
1010
use crate::{codec::ShakeCodec, schnorr_protocol::SchnorrProof};
1111

12-
/// This part tests the functioning of morphisms
12+
/// This part tests the functioning of linear maps
1313
/// as well as the implementation of LinearRelation
1414
#[test]
1515
fn test_discrete_logarithm() {
@@ -73,10 +73,10 @@ fn test_bbs_blind_commitment_computation() {
7373
#[test]
7474
fn noninteractive_discrete_logarithm() {
7575
let mut rng = OsRng;
76-
let (morphismp, witness) = discrete_logarithm(Scalar::random(&mut rng));
76+
let (linear_map, witness) = discrete_logarithm(Scalar::random(&mut rng));
7777

78-
// The SigmaProtocol induced by morphismp
79-
let protocol = SchnorrProof::from(morphismp);
78+
// The SigmaProtocol induced by linear_map
79+
let protocol = SchnorrProof::from(linear_map);
8080
// Fiat-Shamir wrapper
8181
let domain_sep = b"test-fiat-shamir-schnorr";
8282
let nizk = NISigmaProtocol::<SchnorrProof<G>, ShakeCodec<G>>::new(domain_sep, protocol);
@@ -100,10 +100,10 @@ fn noninteractive_discrete_logarithm() {
100100
#[test]
101101
fn noninteractive_dleq() {
102102
let mut rng = OsRng;
103-
let (morphismp, witness) = dleq(G::random(&mut rng), Scalar::random(&mut rng));
103+
let (linear_map, witness) = dleq(G::random(&mut rng), Scalar::random(&mut rng));
104104

105-
// The SigmaProtocol induced by morphismp
106-
let protocol = SchnorrProof::from(morphismp);
105+
// The SigmaProtocol induced by linear_map
106+
let protocol = SchnorrProof::from(linear_map);
107107
// Fiat-Shamir wrapper
108108
let domain_sep = b"test-fiat-shamir-DLEQ";
109109
let nizk = NISigmaProtocol::<SchnorrProof<G>, ShakeCodec<G>>::new(domain_sep, protocol);
@@ -127,14 +127,14 @@ fn noninteractive_dleq() {
127127
#[test]
128128
fn noninteractive_pedersen_commitment() {
129129
let mut rng = OsRng;
130-
let (morphismp, witness) = pedersen_commitment(
130+
let (linear_map, witness) = pedersen_commitment(
131131
G::random(&mut rng),
132132
Scalar::random(&mut rng),
133133
Scalar::random(&mut rng),
134134
);
135135

136-
// The SigmaProtocol induced by morphismp
137-
let protocol = SchnorrProof::from(morphismp);
136+
// The SigmaProtocol induced by linear_map
137+
let protocol = SchnorrProof::from(linear_map);
138138
// Fiat-Shamir wrapper
139139
let domain_sep = b"test-fiat-shamir-pedersen-commitment";
140140
let nizk = NISigmaProtocol::<SchnorrProof<G>, ShakeCodec<G>>::new(domain_sep, protocol);
@@ -158,7 +158,7 @@ fn noninteractive_pedersen_commitment() {
158158
#[test]
159159
fn noninteractive_pedersen_commitment_dleq() {
160160
let mut rng = OsRng;
161-
let (morphismp, witness) = pedersen_commitment_dleq(
161+
let (linear_map, witness) = pedersen_commitment_dleq(
162162
(0..4)
163163
.map(|_| G::random(&mut rng))
164164
.collect::<Vec<_>>()
@@ -171,8 +171,8 @@ fn noninteractive_pedersen_commitment_dleq() {
171171
.unwrap(),
172172
);
173173

174-
// The SigmaProtocol induced by morphismp
175-
let protocol = SchnorrProof::from(morphismp);
174+
// The SigmaProtocol induced by linear_map
175+
let protocol = SchnorrProof::from(linear_map);
176176
// Fiat-Shamir wrapper
177177
let domain_sep = b"test-fiat-shamir-pedersen-commitment-DLEQ";
178178
let nizk = NISigmaProtocol::<SchnorrProof<G>, ShakeCodec<G>>::new(domain_sep, protocol);
@@ -196,7 +196,7 @@ fn noninteractive_pedersen_commitment_dleq() {
196196
#[test]
197197
fn noninteractive_bbs_blind_commitment_computation() {
198198
let mut rng = OsRng;
199-
let (morphismp, witness) = bbs_blind_commitment_computation(
199+
let (linear_map, witness) = bbs_blind_commitment_computation(
200200
(0..4)
201201
.map(|_| G::random(&mut rng))
202202
.collect::<Vec<_>>()
@@ -210,8 +210,8 @@ fn noninteractive_bbs_blind_commitment_computation() {
210210
Scalar::random(&mut rng),
211211
);
212212

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

src/tests/test_utils.rs

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,42 @@ use crate::linear_relation::{msm_pr, LinearRelation};
99
pub fn discrete_logarithm<G: Group + GroupEncoding>(
1010
x: G::Scalar,
1111
) -> (LinearRelation<G>, Vec<G::Scalar>) {
12-
let mut morphismp: LinearRelation<G> = LinearRelation::new();
12+
let mut linear_map: LinearRelation<G> = LinearRelation::new();
1313

14-
let var_x = morphismp.allocate_scalar();
15-
let var_G = morphismp.allocate_element();
14+
let var_x = linear_map.allocate_scalar();
15+
let var_G = linear_map.allocate_element();
1616

17-
let var_X = morphismp.allocate_eq(var_x * var_G);
17+
let var_X = linear_map.allocate_eq(var_x * var_G);
1818

19-
morphismp.set_element(var_G, G::generator());
20-
morphismp.compute_image(&[x]).unwrap();
19+
linear_map.set_element(var_G, G::generator());
20+
linear_map.compute_image(&[x]).unwrap();
2121

22-
let X = morphismp.linear_map.group_elements.get(var_X).unwrap();
22+
let X = linear_map.linear_map.group_elements.get(var_X).unwrap();
2323

2424
assert_eq!(X, G::generator() * x);
25-
(morphismp, vec![x])
25+
(linear_map, vec![x])
2626
}
2727

2828
/// LinearMap for knowledge of a discrete logarithm equality between two pairs.
2929
#[allow(non_snake_case)]
3030
pub fn dleq<G: Group + GroupEncoding>(H: G, x: G::Scalar) -> (LinearRelation<G>, Vec<G::Scalar>) {
31-
let mut morphismp: LinearRelation<G> = LinearRelation::new();
31+
let mut linear_map: LinearRelation<G> = LinearRelation::new();
3232

33-
let var_x = morphismp.allocate_scalar();
34-
let [var_G, var_H] = morphismp.allocate_elements();
33+
let var_x = linear_map.allocate_scalar();
34+
let [var_G, var_H] = linear_map.allocate_elements();
3535

36-
let var_X = morphismp.allocate_eq(var_x * var_G);
37-
let var_Y = morphismp.allocate_eq(var_x * var_H);
36+
let var_X = linear_map.allocate_eq(var_x * var_G);
37+
let var_Y = linear_map.allocate_eq(var_x * var_H);
3838

39-
morphismp.set_elements([(var_G, G::generator()), (var_H, H)]);
40-
morphismp.compute_image(&[x]).unwrap();
39+
linear_map.set_elements([(var_G, G::generator()), (var_H, H)]);
40+
linear_map.compute_image(&[x]).unwrap();
4141

42-
let X = morphismp.linear_map.group_elements.get(var_X).unwrap();
43-
let Y = morphismp.linear_map.group_elements.get(var_Y).unwrap();
42+
let X = linear_map.linear_map.group_elements.get(var_X).unwrap();
43+
let Y = linear_map.linear_map.group_elements.get(var_Y).unwrap();
4444

4545
assert_eq!(X, G::generator() * x);
4646
assert_eq!(Y, H * x);
47-
(morphismp, vec![x])
47+
(linear_map, vec![x])
4848
}
4949

5050
/// LinearMap for knowledge of an opening to a Pederson commitment.
@@ -77,29 +77,29 @@ pub fn pedersen_commitment_dleq<G: Group + GroupEncoding>(
7777
generators: [G; 4],
7878
witness: [G::Scalar; 2],
7979
) -> (LinearRelation<G>, Vec<G::Scalar>) {
80-
let mut morphismp: LinearRelation<G> = LinearRelation::new();
80+
let mut linear_map: LinearRelation<G> = LinearRelation::new();
8181

8282
let X = msm_pr::<G>(&witness, &[generators[0], generators[1]]);
8383
let Y = msm_pr::<G>(&witness, &[generators[2], generators[3]]);
8484

85-
let [var_x, var_r] = morphismp.allocate_scalars();
85+
let [var_x, var_r] = linear_map.allocate_scalars();
8686

87-
let var_Gs = morphismp.allocate_elements::<4>();
88-
let [var_X, var_Y] = morphismp.allocate_elements();
87+
let var_Gs = linear_map.allocate_elements::<4>();
88+
let [var_X, var_Y] = linear_map.allocate_elements();
8989

90-
morphismp.set_elements([
90+
linear_map.set_elements([
9191
(var_Gs[0], generators[0]),
9292
(var_Gs[1], generators[1]),
9393
(var_Gs[2], generators[2]),
9494
(var_Gs[3], generators[3]),
9595
]);
96-
morphismp.set_elements([(var_X, X), (var_Y, Y)]);
96+
linear_map.set_elements([(var_X, X), (var_Y, Y)]);
9797

98-
morphismp.append_equation(var_X, [(var_x, var_Gs[0]), (var_r, var_Gs[1])]);
99-
morphismp.append_equation(var_Y, [(var_x, var_Gs[2]), (var_r, var_Gs[3])]);
98+
linear_map.append_equation(var_X, [(var_x, var_Gs[0]), (var_r, var_Gs[1])]);
99+
linear_map.append_equation(var_Y, [(var_x, var_Gs[2]), (var_r, var_Gs[3])]);
100100

101-
assert!(vec![X, Y] == morphismp.linear_map.evaluate(&witness).unwrap());
102-
(morphismp, witness.to_vec())
101+
assert!(vec![X, Y] == linear_map.linear_map.evaluate(&witness).unwrap());
102+
(linear_map, witness.to_vec())
103103
}
104104

105105
/// LinearMap for knowledge of an opening for use in a BBS commitment.
@@ -110,26 +110,26 @@ pub fn bbs_blind_commitment_computation<G: Group + GroupEncoding>(
110110
[msg_1, msg_2, msg_3]: [G::Scalar; 3],
111111
secret_prover_blind: G::Scalar,
112112
) -> (LinearRelation<G>, Vec<G::Scalar>) {
113-
let mut morphismp = LinearRelation::new();
113+
let mut linear_map = LinearRelation::new();
114114

115115
// these are computed before the proof in the specification
116116
let C = Q_2 * secret_prover_blind + J_1 * msg_1 + J_2 * msg_2 + J_3 * msg_3;
117117

118118
// This is the part that needs to be changed in the specification of blind bbs.
119-
let [var_secret_prover_blind, var_msg_1, var_msg_2, var_msg_3] = morphismp.allocate_scalars();
119+
let [var_secret_prover_blind, var_msg_1, var_msg_2, var_msg_3] = linear_map.allocate_scalars();
120120

121-
let [var_Q_2, var_J_1, var_J_2, var_J_3] = morphismp.allocate_elements();
122-
let var_C = morphismp.allocate_element();
121+
let [var_Q_2, var_J_1, var_J_2, var_J_3] = linear_map.allocate_elements();
122+
let var_C = linear_map.allocate_element();
123123

124-
morphismp.set_elements([
124+
linear_map.set_elements([
125125
(var_Q_2, Q_2),
126126
(var_J_1, J_1),
127127
(var_J_2, J_2),
128128
(var_J_3, J_3),
129129
(var_C, C),
130130
]);
131131

132-
morphismp.append_equation(
132+
linear_map.append_equation(
133133
var_C,
134134
[
135135
(var_secret_prover_blind, var_Q_2),
@@ -141,6 +141,6 @@ pub fn bbs_blind_commitment_computation<G: Group + GroupEncoding>(
141141

142142
let witness = vec![secret_prover_blind, msg_1, msg_2, msg_3];
143143

144-
assert!(vec![C] == morphismp.linear_map.evaluate(&witness).unwrap());
145-
(morphismp, witness)
144+
assert!(vec![C] == linear_map.linear_map.evaluate(&witness).unwrap());
145+
(linear_map, witness)
146146
}

0 commit comments

Comments
 (0)