Skip to content

Commit cf1bb17

Browse files
committed
refactor: better naming of methods
this includes: Shake -> Shake128, _translated -> _shifted constraints -> linear_combinations prandom -> random_group_elt srandom -> random_scalar_elt
1 parent d9420e2 commit cf1bb17

File tree

14 files changed

+294
-324
lines changed

14 files changed

+294
-324
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This library provides a flexible framework for creating zero-knowledge proofs fo
1010

1111
```rust
1212
use sigma_rs::{LinearRelation, Protocol, ProtocolWitness, Nizk};
13-
use sigma_rs::codec::ShakeCodec;
13+
use sigma_rs::codec::Shake128DuplexSponge;
1414
use curve25519_dalek::RistrettoPoint as G;
1515

1616
// Prove knowledge of (x, r) such that C = x·G + r·H (Pedersen commitment)

examples/simple_composition.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use curve25519_dalek::scalar::Scalar;
55
use group::Group;
66
use rand::rngs::OsRng;
77
use sigma_rs::{
8-
codec::ShakeCodec,
8+
codec::Shake128DuplexSponge,
99
composition::{Protocol, ProtocolWitness},
1010
errors::Error,
1111
LinearRelation, Nizk,
@@ -54,7 +54,7 @@ fn prove(P1: G, x2: Scalar, H: G) -> ProofResult<Vec<u8>> {
5454

5555
let protocol = create_relation(P1, P2, Q, H);
5656
let witness = ProtocolWitness::Or(1, vec![ProtocolWitness::Simple(vec![x2])]);
57-
let nizk = Nizk::<_, ShakeCodec<G>>::new(b"or_proof_example", protocol);
57+
let nizk = Nizk::<_, Shake128DuplexSponge<G>>::new(b"or_proof_example", protocol);
5858

5959
nizk.prove_batchable(&witness, &mut OsRng)
6060
}
@@ -63,7 +63,7 @@ fn prove(P1: G, x2: Scalar, H: G) -> ProofResult<Vec<u8>> {
6363
#[allow(non_snake_case)]
6464
fn verify(P1: G, P2: G, Q: G, H: G, proof: &[u8]) -> ProofResult<()> {
6565
let protocol = create_relation(P1, P2, Q, H);
66-
let nizk = Nizk::<_, ShakeCodec<G>>::new(b"or_proof_example", protocol);
66+
let nizk = Nizk::<_, Shake128DuplexSponge<G>>::new(b"or_proof_example", protocol);
6767

6868
nizk.verify_batchable(proof)
6969
}

src/codec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,4 @@ where
118118
pub type KeccakByteSchnorrCodec<G> = ByteSchnorrCodec<G, KeccakDuplexSponge>;
119119

120120
/// Type alias for a SHAKE-based ByteSchnorrCodec.
121-
pub type ShakeCodec<G> = ByteSchnorrCodec<G, ShakeDuplexSponge>;
121+
pub type Shake128DuplexSponge<G> = ByteSchnorrCodec<G, ShakeDuplexSponge>;

src/linear_relation/mod.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::marker::PhantomData;
1616
use ff::Field;
1717
use group::{Group, GroupEncoding};
1818

19-
use crate::codec::ShakeCodec;
19+
use crate::codec::Shake128DuplexSponge;
2020
use crate::errors::Error;
2121
use crate::schnorr_protocol::SchnorrProof;
2222
use crate::Nizk;
@@ -224,7 +224,7 @@ impl<G: Group> FromIterator<(GroupVar<G>, G)> for GroupMap<G> {
224224
#[derive(Clone, Default, Debug)]
225225
pub struct LinearMap<G: Group> {
226226
/// The set of linear combination constraints (equations).
227-
pub constraints: Vec<LinearCombination<G>>,
227+
pub linear_combinations: Vec<LinearCombination<G>>,
228228
/// The list of group elements referenced in the linear map.
229229
///
230230
/// Uninitialized group elements are presented with `None`.
@@ -263,7 +263,7 @@ impl<G: Group> LinearMap<G> {
263263
/// and zero allocated scalars and elements.
264264
pub fn new() -> Self {
265265
Self {
266-
constraints: Vec::new(),
266+
linear_combinations: Vec::new(),
267267
group_elements: GroupMap::default(),
268268
num_scalars: 0,
269269
num_elements: 0,
@@ -272,15 +272,15 @@ impl<G: Group> LinearMap<G> {
272272

273273
/// Returns the number of constraints (equations) in this linear map.
274274
pub fn num_constraints(&self) -> usize {
275-
self.constraints.len()
275+
self.linear_combinations.len()
276276
}
277277

278278
/// Adds a new linear combination constraint to the linear map.
279279
///
280280
/// # Parameters
281281
/// - `lc`: The [`LinearCombination`] to add.
282282
pub fn append(&mut self, lc: LinearCombination<G>) {
283-
self.constraints.push(lc);
283+
self.linear_combinations.push(lc);
284284
}
285285

286286
/// Evaluates all linear combinations in the linear map with the provided scalars.
@@ -292,7 +292,7 @@ impl<G: Group> LinearMap<G> {
292292
///
293293
/// A vector of group elements, each being the result of evaluating one linear combination with the scalars.
294294
pub fn evaluate(&self, scalars: &[<G as Group>::Scalar]) -> Result<Vec<G>, Error> {
295-
self.constraints
295+
self.linear_combinations
296296
.iter()
297297
.map(|lc| {
298298
// TODO: The multiplication by the (public) weight is potentially wasteful in the
@@ -343,7 +343,7 @@ pub struct CanonicalLinearRelation<G: Group + GroupEncoding> {
343343
pub image: Vec<G>,
344344
/// The constraints, where each constraint is a vector of (scalar_var, group_var) pairs
345345
/// representing the right-hand side of the equation
346-
pub constraints: Vec<Vec<(ScalarVar<G>, GroupVar<G>)>>,
346+
pub linear_combinations: Vec<Vec<(ScalarVar<G>, GroupVar<G>)>>,
347347
/// The group elements map
348348
pub group_elements: GroupMap<G>,
349349
/// Number of scalar variables
@@ -355,7 +355,7 @@ impl<G: Group + GroupEncoding> CanonicalLinearRelation<G> {
355355
pub fn new() -> Self {
356356
Self {
357357
image: Vec::new(),
358-
constraints: Vec::new(),
358+
linear_combinations: Vec::new(),
359359
group_elements: GroupMap::default(),
360360
num_scalars: 0,
361361
}
@@ -435,7 +435,7 @@ impl<G: Group + GroupEncoding> CanonicalLinearRelation<G> {
435435

436436
// Only include constraints that are non-trivial (not zero constraints)
437437
self.image.push(canonical_image);
438-
self.constraints.push(rhs_terms);
438+
self.linear_combinations.push(rhs_terms);
439439

440440
Ok(())
441441
}
@@ -471,7 +471,7 @@ impl<G: Group + GroupEncoding> CanonicalLinearRelation<G> {
471471
// Build constraint data in the same order as original
472472
let mut constraint_data = Vec::new();
473473

474-
for (image_elem, constraint_terms) in iter::zip(&self.image, &self.constraints) {
474+
for (image_elem, constraint_terms) in iter::zip(&self.image, &self.linear_combinations) {
475475
// First, add the left-hand side (image) element
476476
let lhs_index = repr_index(image_elem.to_bytes());
477477

@@ -520,7 +520,7 @@ impl<G: Group + GroupEncoding> TryFrom<LinearRelation<G>> for CanonicalLinearRel
520520
fn try_from(relation: LinearRelation<G>) -> Result<Self, Self::Error> {
521521
assert_eq!(
522522
relation.image.len(),
523-
relation.linear_map.constraints.len(),
523+
relation.linear_map.linear_combinations.len(),
524524
"Number of equations and image variables must match"
525525
);
526526

@@ -532,7 +532,7 @@ impl<G: Group + GroupEncoding> TryFrom<LinearRelation<G>> for CanonicalLinearRel
532532
HashMap::new();
533533

534534
// Process each constraint using the modular helper method
535-
for (image_var, equation) in iter::zip(&relation.image, &relation.linear_map.constraints) {
535+
for (image_var, equation) in iter::zip(&relation.image, &relation.linear_map.linear_combinations) {
536536
canonical.process_constraint(
537537
*image_var,
538538
equation,
@@ -683,7 +683,7 @@ where
683683
}
684684

685685
for (lc, lhs) in iter::zip(
686-
self.linear_map.constraints.as_slice(),
686+
self.linear_map.linear_combinations.as_slice(),
687687
self.image.as_slice(),
688688
) {
689689
// TODO: The multiplication by the (public) weight is potentially wasteful in the
@@ -761,7 +761,7 @@ where
761761
/// let proof = nizk.prove_batchable(&vec![x], &mut OsRng).unwrap();
762762
/// assert!(nizk.verify_batchable(&proof).is_ok());
763763
/// ```
764-
pub fn into_nizk(self, session_identifier: &[u8]) -> Nizk<SchnorrProof<G>, ShakeCodec<G>>
764+
pub fn into_nizk(self, session_identifier: &[u8]) -> Nizk<SchnorrProof<G>, Shake128DuplexSponge<G>>
765765
where
766766
G: group::GroupEncoding,
767767
{

src/schnorr_protocol.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ impl<G: Group + GroupEncoding> SchnorrProof<G> {
3333
}
3434

3535
pub fn commitment_length(&self) -> usize {
36-
self.0.constraints.len()
36+
self.0.linear_combinations.len()
3737
}
3838

3939
/// Evaluate the canonical linear relation with the provided scalars
4040
fn evaluate(&self, scalars: &[G::Scalar]) -> Result<Vec<G>, Error> {
4141
self.0
42-
.constraints
42+
.linear_combinations
4343
.iter()
4444
.map(|constraint| {
4545
let mut result = G::identity();

src/tests/composition.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use super::test_utils::{
66
bbs_blind_commitment_computation, discrete_logarithm, dleq, pedersen_commitment,
77
pedersen_commitment_dleq,
88
};
9-
use crate::codec::ShakeCodec;
9+
use crate::codec::Shake128DuplexSponge;
1010
use crate::composition::{Protocol, ProtocolWitness};
1111
use crate::fiat_shamir::Nizk;
1212
use crate::schnorr_protocol::SchnorrProof;
@@ -85,7 +85,7 @@ fn composition_proof_correct() {
8585
let protocol = Protocol::And(vec![or_protocol1, simple_protocol1, and_protocol1]);
8686
let witness = ProtocolWitness::And(vec![or_witness1, simple_witness1, and_witness1]);
8787

88-
let nizk = Nizk::<Protocol<RistrettoPoint>, ShakeCodec<G>>::new(domain_sep, protocol);
88+
let nizk = Nizk::<Protocol<RistrettoPoint>, Shake128DuplexSponge<G>>::new(domain_sep, protocol);
8989

9090
// Batchable and compact proofs
9191
let proof_batchable_bytes = nizk.prove_batchable(&witness, &mut OsRng).unwrap();

0 commit comments

Comments
 (0)