Skip to content

Commit 078b0b7

Browse files
Relax Arc requirement for input sets (#101)
This PR relaxes the `Arc` requirement for input sets. Specifically, it removes the requirement that the caller use an `Arc` wrapper for a `TriptychInputSet` in order to use it to generate a statement. Instead, this wrapping is handled internally. Partially addresses #65. BREAKING CHANGE: Updates the public API.
1 parent e71fb67 commit 078b0b7

File tree

8 files changed

+22
-22
lines changed

8 files changed

+22
-22
lines changed

benches/parallel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn generate_data<R: CryptoRngCore>(
6363
offsets.push(r_offset * params.get_G1());
6464
M1[witness.get_l() as usize] = witness.compute_auxiliary_verification_key() + offsets.last().unwrap();
6565
}
66-
let input_set = Arc::new(TriptychInputSet::new(&M, &M1).unwrap());
66+
let input_set = TriptychInputSet::new(&M, &M1).unwrap();
6767

6868
// Generate statements
6969
let mut statements = Vec::with_capacity(b);

benches/triptych.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn generate_data<R: CryptoRngCore>(
5353
for witness in &witnesses {
5454
M[witness.get_l() as usize] = witness.compute_verification_key();
5555
}
56-
let input_set = Arc::new(TriptychInputSet::new(&M).unwrap());
56+
let input_set = TriptychInputSet::new(&M).unwrap();
5757

5858
// Generate statements
5959
let mut statements = Vec::with_capacity(b);

examples/ringct.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,8 @@ mod test {
6666
let witness = TriptychWitness::new(&params, index, &signing_key, &(commitment_mask - offset_mask)).unwrap();
6767

6868
// We can also set up the input set and statement
69-
// The input set is `Arc`-wrapped since it's likely it could be reused
7069
// The linkable ring signature also comes equipped with a linking tag; the library can compute it for us
71-
let input_set = Arc::new(TriptychInputSet::new(&output_keys, &value_commitments).unwrap());
70+
let input_set = TriptychInputSet::new(&output_keys, &value_commitments).unwrap();
7271
let statement = TriptychStatement::new(&params, &input_set, &offset, &witness.compute_linking_tag()).unwrap();
7372

7473
// The proof needs a transcript associated to it

src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
//! let witness = TriptychWitness::random(&params, &mut rng);
8787
//!
8888
//! // Generate an input set of random verification keys, placing ours at the chosen index
89-
//! // This is `Arc`-wrapped to facilitate efficient reuse!
9089
//! let M = (0..params.get_N())
9190
//! .map(|i| {
9291
//! if i == witness.get_l() {
@@ -96,7 +95,7 @@
9695
//! }
9796
//! })
9897
//! .collect::<Vec<RistrettoPoint>>();
99-
//! let input_set = Arc::new(TriptychInputSet::new(&M).unwrap());
98+
//! let input_set = TriptychInputSet::new(&M).unwrap();
10099
//!
101100
//! // Generate the statement, which includes the verification key vector and linking tag
102101
//! let J = witness.compute_linking_tag();

src/parallel/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
//! let offset = Scalar::random(&mut rng) * params.get_G1();
4444
//!
4545
//! // Generate an input set of random verification keys, placing ours at the chosen index
46-
//! // This is `Arc`-wrapped to facilitate efficient reuse!
4746
//! let M = (0..params.get_N())
4847
//! .map(|i| {
4948
//! if i == witness.get_l() {
@@ -63,7 +62,7 @@
6362
//! }
6463
//! })
6564
//! .collect::<Vec<RistrettoPoint>>();
66-
//! let input_set = Arc::new(TriptychInputSet::new(&M, &M1).unwrap());
65+
//! let input_set = TriptychInputSet::new(&M, &M1).unwrap();
6766
//!
6867
//! // Generate the statement, which includes the verification key vectors and linking tag
6968
//! let J = witness.compute_linking_tag();

src/parallel/statement.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use crate::{parallel::TriptychParameters, Transcript, TRANSCRIPT_HASH_BYTES};
1515
#[allow(non_snake_case)]
1616
#[derive(Clone, Debug, Eq, PartialEq)]
1717
pub struct TriptychInputSet {
18-
M: Vec<RistrettoPoint>,
19-
M1: Vec<RistrettoPoint>,
18+
M: Arc<Vec<RistrettoPoint>>,
19+
M1: Arc<Vec<RistrettoPoint>>,
2020
hash: Vec<u8>,
2121
}
2222

@@ -99,8 +99,8 @@ impl TriptychInputSet {
9999
transcript.challenge_bytes(b"hash", &mut hash);
100100

101101
Ok(Self {
102-
M: M.to_vec(),
103-
M1: M1.to_vec(),
102+
M: Arc::new(M.to_vec()),
103+
M1: Arc::new(M1.to_vec()),
104104
hash,
105105
})
106106
}
@@ -130,7 +130,7 @@ impl TriptychInputSet {
130130
#[derive(Clone, Eq, PartialEq)]
131131
pub struct TriptychStatement {
132132
params: Arc<TriptychParameters>,
133-
input_set: Arc<TriptychInputSet>,
133+
input_set: TriptychInputSet,
134134
offset: RistrettoPoint,
135135
J: RistrettoPoint,
136136
hash: Vec<u8>,
@@ -162,7 +162,7 @@ impl TriptychStatement {
162162
#[allow(non_snake_case)]
163163
pub fn new(
164164
params: &Arc<TriptychParameters>,
165-
input_set: &Arc<TriptychInputSet>,
165+
input_set: &TriptychInputSet,
166166
offset: &RistrettoPoint,
167167
J: &RistrettoPoint,
168168
) -> Result<Self, StatementError> {
@@ -208,7 +208,7 @@ impl TriptychStatement {
208208
}
209209

210210
/// Get the input set for this [`TriptychStatement`].
211-
pub fn get_input_set(&self) -> &Arc<TriptychInputSet> {
211+
pub fn get_input_set(&self) -> &TriptychInputSet {
212212
&self.input_set
213213
}
214214

src/proof.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ mod test {
998998
for witness in &witnesses {
999999
M[witness.get_l() as usize] = witness.compute_verification_key();
10001000
}
1001-
let input_set = Arc::new(TriptychInputSet::new(&M).unwrap());
1001+
let input_set = TriptychInputSet::new(&M).unwrap();
10021002

10031003
// Generate statements
10041004
let mut statements = Vec::with_capacity(b);
@@ -1282,7 +1282,7 @@ mod test {
12821282
let mut M = statements[0].get_input_set().get_keys().to_vec();
12831283
let index = ((witnesses[0].get_l() + 1) % witnesses[0].get_params().get_N()) as usize;
12841284
M[index] = RistrettoPoint::random(&mut rng);
1285-
let evil_input_set = Arc::new(TriptychInputSet::new(&M).unwrap());
1285+
let evil_input_set = TriptychInputSet::new(&M).unwrap();
12861286
let evil_statement =
12871287
TriptychStatement::new(statements[0].get_params(), &evil_input_set, statements[0].get_J()).unwrap();
12881288

src/statement.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{Transcript, TriptychParameters, TRANSCRIPT_HASH_BYTES};
1515
#[allow(non_snake_case)]
1616
#[derive(Clone, Debug, Eq, PartialEq)]
1717
pub struct TriptychInputSet {
18-
M: Vec<RistrettoPoint>,
18+
M: Arc<Vec<RistrettoPoint>>,
1919
hash: Vec<u8>,
2020
}
2121

@@ -74,7 +74,10 @@ impl TriptychInputSet {
7474
let mut hash = vec![0u8; TRANSCRIPT_HASH_BYTES];
7575
transcript.challenge_bytes(b"hash", &mut hash);
7676

77-
Ok(Self { M: M.to_vec(), hash })
77+
Ok(Self {
78+
M: Arc::new(M.to_vec()),
79+
hash,
80+
})
7881
}
7982

8083
/// Get the verification keys for this [`TriptychInputSet`].
@@ -96,7 +99,7 @@ impl TriptychInputSet {
9699
#[derive(Clone, Eq, PartialEq)]
97100
pub struct TriptychStatement {
98101
params: Arc<TriptychParameters>,
99-
input_set: Arc<TriptychInputSet>,
102+
input_set: TriptychInputSet,
100103
J: RistrettoPoint,
101104
hash: Vec<u8>,
102105
}
@@ -127,7 +130,7 @@ impl TriptychStatement {
127130
#[allow(non_snake_case)]
128131
pub fn new(
129132
params: &Arc<TriptychParameters>,
130-
input_set: &Arc<TriptychInputSet>,
133+
input_set: &TriptychInputSet,
131134
J: &RistrettoPoint,
132135
) -> Result<Self, StatementError> {
133136
// Check that the input vector is valid against the parameters
@@ -161,7 +164,7 @@ impl TriptychStatement {
161164
}
162165

163166
/// Get the input set for this [`TriptychStatement`].
164-
pub fn get_input_set(&self) -> &Arc<TriptychInputSet> {
167+
pub fn get_input_set(&self) -> &TriptychInputSet {
165168
&self.input_set
166169
}
167170

0 commit comments

Comments
 (0)