Skip to content

Commit c197096

Browse files
olegnnlovesh
authored andcommitted
More type replacements
1 parent dddb5bf commit c197096

File tree

34 files changed

+246
-222
lines changed

34 files changed

+246
-222
lines changed

bbs_plus/src/proof.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ mod tests {
549549

550550
fn sig_setup<R: RngCore>(
551551
rng: &mut R,
552-
message_count: usize,
552+
message_count: u32,
553553
) -> (
554554
Vec<Fr>,
555555
SignatureParamsG1<Bls12_381>,
@@ -976,7 +976,7 @@ mod tests {
976976
)
977977
.unwrap();
978978
let proof_1 = pok_1.gen_proof(&challenge).unwrap();
979-
for i in 0..message_count {
979+
for i in 0..message_count as usize {
980980
assert_eq!(
981981
*proof_1
982982
.get_resp_for_message(i, &revealed_indices_1)
@@ -1089,7 +1089,7 @@ mod tests {
10891089
);
10901090

10911091
// Reveal one message only
1092-
for i in 0..message_count {
1092+
for i in 0..message_count as usize {
10931093
let mut revealed_indices = BTreeSet::new();
10941094
revealed_indices.insert(i);
10951095
let pok = PoKOfSignatureG1Protocol::init(
@@ -1106,7 +1106,7 @@ mod tests {
11061106
)
11071107
.unwrap();
11081108
let proof = pok.gen_proof(&challenge).unwrap();
1109-
for j in 0..message_count {
1109+
for j in 0..message_count as usize {
11101110
if i == j {
11111111
assert!(proof.get_resp_for_message(j, &revealed_indices).is_err());
11121112
} else if i < j {

bbs_plus/src/proof_23.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ mod tests {
433433

434434
fn sig_setup<R: RngCore>(
435435
rng: &mut R,
436-
message_count: usize,
436+
message_count: u32,
437437
) -> (
438438
Vec<Fr>,
439439
SignatureParams23G1<Bls12_381>,
@@ -739,7 +739,7 @@ mod tests {
739739
)
740740
.unwrap();
741741
let proof_1 = pok_1.gen_proof(&challenge).unwrap();
742-
for i in 0..message_count {
742+
for i in 0..message_count as usize {
743743
assert_eq!(
744744
*proof_1
745745
.get_resp_for_message(i, &revealed_indices_1)
@@ -856,7 +856,7 @@ mod tests {
856856
);
857857

858858
// Reveal one message only
859-
for i in 0..message_count {
859+
for i in 0..message_count as usize {
860860
let mut revealed_indices = BTreeSet::new();
861861
revealed_indices.insert(i);
862862
let pok = PoKOfSignature23G1Protocol::init(
@@ -875,7 +875,7 @@ mod tests {
875875
)
876876
.unwrap();
877877
let proof = pok.gen_proof(&challenge).unwrap();
878-
for j in 0..message_count {
878+
for j in 0..message_count as usize {
879879
if i == j {
880880
assert!(proof.get_resp_for_message(j, &revealed_indices).is_err());
881881
} else if i < j {

bbs_plus/src/proof_23_alternate.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ mod tests {
457457

458458
fn sig_setup<R: RngCore>(
459459
rng: &mut R,
460-
message_count: usize,
460+
message_count: u32,
461461
) -> (
462462
Vec<Fr>,
463463
SignatureParams23G1<Bls12_381>,
@@ -515,7 +515,7 @@ mod tests {
515515
)
516516
.unwrap();
517517
let proof_1 = pok_1.gen_proof(&challenge).unwrap();
518-
for i in 0..message_count {
518+
for i in 0..message_count as usize {
519519
assert_eq!(
520520
*proof_1
521521
.get_resp_for_message(i, &revealed_indices_1)
@@ -628,7 +628,7 @@ mod tests {
628628
);
629629

630630
// Reveal one message only
631-
for i in 0..message_count {
631+
for i in 0..message_count as usize {
632632
let mut revealed_indices = BTreeSet::new();
633633
revealed_indices.insert(i);
634634
let pok = PoKOfSignature23G1Protocol::init(
@@ -645,7 +645,7 @@ mod tests {
645645
)
646646
.unwrap();
647647
let proof = pok.gen_proof(&challenge).unwrap();
648-
for j in 0..message_count {
648+
for j in 0..message_count as usize {
649649
if i == j {
650650
assert!(proof.get_resp_for_message(j, &revealed_indices).is_err());
651651
} else if i < j {

bbs_plus/src/setup.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ use zeroize::{Zeroize, ZeroizeOnDrop};
6363

6464
use core::iter::once;
6565
use dock_crypto_utils::{
66+
affine_group_from_slices,
6667
concat_slices, hashing_utils::projective_group_elem_from_try_and_incr, iter::*,
6768
misc::seq_pairs_satisfy, serde_utils::*, try_iter::CheckLeft,
6869
};
@@ -244,21 +245,19 @@ macro_rules! impl_sig_params {
244245
/// Generate params by hashing a known string. The hash function is vulnerable to timing
245246
/// attack but since all this is public knowledge, it is fine.
246247
/// This is useful if people need to be convinced that the discrete log of group elements wrt each other is not known.
247-
pub fn new<D: Digest>(label: &[u8], message_count: usize) -> Self {
248+
pub fn new<D: Digest>(label: &[u8], message_count: u32) -> Self {
248249
assert_ne!(message_count, 0);
249250
// Need message_count+2 elements of signature group and 1 element of other group
250-
let mut sig_group_elems = Vec::with_capacity(message_count + 2);
251+
let mut sig_group_elems = Vec::with_capacity(message_count as usize + 2);
251252
// Group element by hashing `label`||`g1` as string.
252253
let g1 = projective_group_elem_from_try_and_incr::<E::$group_affine, D>(
253254
&concat_slices![label, b" : g1"],
254255
);
255256
// h_0 and h[i] for i in 1 to message_count
256257
let mut h = cfg_into_iter!((0..=message_count))
257-
.map(|i| {
258-
projective_group_elem_from_try_and_incr::<E::$group_affine, D>(
259-
&concat_slices![label, b" : h_", (i as u32).to_le_bytes()],
260-
)
261-
})
258+
.map(u32::to_le_bytes)
259+
.map(|i| affine_group_from_slices!(label, b" : h_", i))
260+
.map(E::$group_affine::into)
262261
.collect::<Vec<E::$group_projective>>();
263262
sig_group_elems.push(g1);
264263
sig_group_elems.append(&mut h);
@@ -268,10 +267,8 @@ macro_rules! impl_sig_params {
268267
let g1 = sig_group_elems.remove(0);
269268
let h_0 = sig_group_elems.remove(0);
270269

271-
let g2 = projective_group_elem_from_try_and_incr::<E::$other_group_affine, D>(
272-
&concat_slices![label, b" : g2"],
273-
)
274-
.into_affine();
270+
let g2: E::$other_group_affine = affine_group_from_slices!(label, b" : g2");
271+
275272
Self {
276273
g1,
277274
g2,
@@ -281,7 +278,7 @@ macro_rules! impl_sig_params {
281278
}
282279

283280
/// Generate params using a random number generator
284-
pub fn generate_using_rng<R>(rng: &mut R, message_count: usize) -> Self
281+
pub fn generate_using_rng<R>(rng: &mut R, message_count: u32) -> Self
285282
where
286283
R: RngCore,
287284
{
@@ -516,7 +513,7 @@ impl<E: Pairing> SignatureParams23G1<E> {
516513
/// Generate params by hashing a known string. The hash function is vulnerable to timing
517514
/// attack but since all this is public knowledge, it is fine.
518515
/// This is useful if people need to be convinced that the discrete log of group elements wrt each other is not known.
519-
pub fn new<D: Digest>(label: &[u8], message_count: usize) -> Self {
516+
pub fn new<D: Digest>(label: &[u8], message_count: u32) -> Self {
520517
assert_ne!(message_count, 0);
521518
// Group element by hashing `label`||`g1` as string.
522519
let g1 = projective_group_elem_from_try_and_incr::<E::G1Affine, D>(&concat_slices![
@@ -545,7 +542,7 @@ impl<E: Pairing> SignatureParams23G1<E> {
545542
}
546543

547544
/// Generate params using a random number generator
548-
pub fn generate_using_rng<R>(rng: &mut R, message_count: usize) -> Self
545+
pub fn generate_using_rng<R>(rng: &mut R, message_count: u32) -> Self
549546
where
550547
R: RngCore,
551548
{
@@ -636,7 +633,7 @@ mod tests {
636633
let label_1 = "test1".as_bytes();
637634
let params_1 = $params::<Bls12_381>::new::<Blake2b512>(&label_1, $message_count);
638635
assert!(params_1.is_valid());
639-
assert_eq!(params_1.h.len(), $message_count);
636+
assert_eq!(params_1.h.len(), $message_count as usize);
640637

641638
// Same label should generate same params
642639
let params_1_again = $params::<Bls12_381>::new::<Blake2b512>(&label_1, $message_count);

bbs_plus/src/threshold/cointoss.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl<F: PrimeField, const SALT_SIZE: usize> Party<F, SALT_SIZE> {
4040
pub fn commit<R: RngCore>(
4141
rng: &mut R,
4242
id: ParticipantId,
43-
batch_size: usize,
43+
batch_size: u32,
4444
protocol_id: Vec<u8>,
4545
) -> (Self, Commitments) {
4646
let shares_and_salts = (0..batch_size)
@@ -186,7 +186,7 @@ pub mod tests {
186186
fn cointoss() {
187187
let mut rng = StdRng::seed_from_u64(0u64);
188188

189-
fn check<const SALT_SIZE: usize>(rng: &mut StdRng, batch_size: usize, num_parties: u16) {
189+
fn check<const SALT_SIZE: usize>(rng: &mut StdRng, batch_size: u32, num_parties: u16) {
190190
let label = b"test".to_vec();
191191
let mut parties = vec![];
192192
let mut commitments = vec![];

bbs_plus/src/threshold/multiplication_phase.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use oblivious_transfer_protocols::{
2727
pub struct Phase2<F: PrimeField, const KAPPA: u16, const STATISTICAL_SECURITY_PARAMETER: u16> {
2828
pub id: ParticipantId,
2929
/// Number of threshold signatures being generated in a single batch.
30-
pub batch_size: u64,
30+
pub batch_size: u32,
3131
/// Transcripts to record protocol interactions with each participant and later used to generate random challenges
3232
pub transcripts: BTreeMap<ParticipantId, Merlin>,
3333
pub ote_params: MultiplicationOTEParams<KAPPA, STATISTICAL_SECURITY_PARAMETER>,
@@ -69,7 +69,7 @@ impl<F: PrimeField, const KAPPA: u16, const STATISTICAL_SECURITY_PARAMETER: u16>
6969
gadget_vector: &GadgetVector<F, KAPPA, STATISTICAL_SECURITY_PARAMETER>,
7070
) -> Result<(Self, BTreeMap<ParticipantId, Message1<F>>), BBSPlusError> {
7171
assert_eq!(masked_signing_key_share.len(), masked_r.len());
72-
let batch_size = masked_signing_key_share.len() as u64;
72+
let batch_size = masked_signing_key_share.len() as u32;
7373

7474
let mut transcripts = BTreeMap::<ParticipantId, Merlin>::new();
7575
let mut multiplication_party1 =
@@ -154,7 +154,7 @@ impl<F: PrimeField, const KAPPA: u16, const STATISTICAL_SECURITY_PARAMETER: u16>
154154

155155
let (shares, tau, r, gamma_a) =
156156
party1.receive::<D>(U, rlc, gamma, trans, &gadget_vector)?;
157-
debug_assert_eq!(shares.len() as u64, 2 * self.batch_size);
157+
debug_assert_eq!(shares.len() as u32, 2 * self.batch_size);
158158
let mut z_A_0 = Vec::with_capacity(self.batch_size as usize);
159159
let mut z_A_1 = Vec::with_capacity(self.batch_size as usize);
160160
for (i, share) in shares.0.into_iter().enumerate() {
@@ -185,7 +185,7 @@ impl<F: PrimeField, const KAPPA: u16, const STATISTICAL_SECURITY_PARAMETER: u16>
185185
let party2 = self.multiplication_party2.remove(&sender_id).unwrap();
186186
let trans = self.transcripts.get_mut(&sender_id).unwrap();
187187
let shares = party2.receive::<D>(tau, rlc, gamma, trans, &gadget_vector)?;
188-
debug_assert_eq!(shares.len() as u64, 2 * self.batch_size);
188+
debug_assert_eq!(shares.len() as u32, 2 * self.batch_size);
189189
let mut z_B_0 = Vec::with_capacity(self.batch_size as usize);
190190
let mut z_B_1 = Vec::with_capacity(self.batch_size as usize);
191191
for (i, share) in shares.0.into_iter().enumerate() {

bbs_plus/src/threshold/randomness_generation_phase.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use oblivious_transfer_protocols::ParticipantId;
1414
pub struct Phase1<F: PrimeField, const SALT_SIZE: usize> {
1515
pub id: ParticipantId,
1616
/// Number of threshold signatures being generated in a single batch.
17-
pub batch_size: u64,
17+
pub batch_size: u32,
1818
pub r: Vec<F>,
1919
/// Protocols to generate shares of random values used in signature like `e`
2020
pub commitment_protocol: super::cointoss::Party<F, SALT_SIZE>,

bbs_plus/src/threshold/threshold_bbs.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use oblivious_transfer_protocols::ParticipantId;
2424
#[derive(Clone, Debug, PartialEq, CanonicalSerialize, CanonicalDeserialize)]
2525
pub struct Phase1Output<F: PrimeField> {
2626
pub id: ParticipantId,
27-
pub batch_size: u64,
27+
pub batch_size: u32,
2828
pub r: Vec<F>,
2929
pub e: Vec<F>,
3030
/// Additive shares of the signing key masked by a random `alpha`
@@ -47,7 +47,7 @@ pub struct BBSSignatureShare<E: Pairing> {
4747
impl<F: PrimeField, const SALT_SIZE: usize> Phase1<F, SALT_SIZE> {
4848
pub fn init_for_bbs<R: RngCore>(
4949
rng: &mut R,
50-
batch_size: usize,
50+
batch_size: u32,
5151
id: ParticipantId,
5252
others: BTreeSet<ParticipantId>,
5353
protocol_id: Vec<u8>,
@@ -65,7 +65,7 @@ impl<F: PrimeField, const SALT_SIZE: usize> Phase1<F, SALT_SIZE> {
6565
Ok((
6666
Self {
6767
id,
68-
batch_size: batch_size as u64,
68+
batch_size: batch_size,
6969
r,
7070
commitment_protocol,
7171
zero_sharing_protocol,
@@ -86,7 +86,7 @@ impl<F: PrimeField, const SALT_SIZE: usize> Phase1<F, SALT_SIZE> {
8686
let r = self.r.clone();
8787
let (others, randomness, masked_signing_key_share, masked_r) =
8888
self.compute_randomness_and_arguments_for_multiplication::<D>(signing_key)?;
89-
debug_assert_eq!(randomness.len() as u64, batch_size);
89+
debug_assert_eq!(randomness.len() as u32, batch_size);
9090
let e = randomness;
9191
Ok(Phase1Output {
9292
id,
@@ -307,7 +307,7 @@ pub mod tests {
307307
}
308308
println!("Phase 1 took {:?}", start.elapsed());
309309

310-
assert_eq!(expected_sk, sk * Fr::from(sig_batch_size as u64));
310+
assert_eq!(expected_sk, sk * Fr::from(sig_batch_size));
311311
for i in 1..threshold_signers {
312312
assert_eq!(round1outs[0].e, round1outs[i as usize].e);
313313
}

bbs_plus/src/threshold/threshold_bbs_plus.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use super::{multiplication_phase::Phase2Output, utils::compute_R_and_u};
2525
#[derive(Clone, Debug, PartialEq, CanonicalSerialize, CanonicalDeserialize)]
2626
pub struct Phase1Output<F: PrimeField> {
2727
pub id: ParticipantId,
28-
pub batch_size: u64,
28+
pub batch_size: u32,
2929
pub r: Vec<F>,
3030
pub e: Vec<F>,
3131
pub s: Vec<F>,
@@ -50,7 +50,7 @@ pub struct BBSPlusSignatureShare<E: Pairing> {
5050
impl<F: PrimeField, const SALT_SIZE: usize> Phase1<F, SALT_SIZE> {
5151
pub fn init_for_bbs_plus<R: RngCore>(
5252
rng: &mut R,
53-
batch_size: usize,
53+
batch_size: u32,
5454
id: ParticipantId,
5555
others: BTreeSet<ParticipantId>,
5656
protocol_id: Vec<u8>,
@@ -68,7 +68,7 @@ impl<F: PrimeField, const SALT_SIZE: usize> Phase1<F, SALT_SIZE> {
6868
Ok((
6969
Self {
7070
id,
71-
batch_size: batch_size as u64,
71+
batch_size: batch_size,
7272
r,
7373
commitment_protocol,
7474
zero_sharing_protocol,
@@ -89,7 +89,7 @@ impl<F: PrimeField, const SALT_SIZE: usize> Phase1<F, SALT_SIZE> {
8989
let r = self.r.clone();
9090
let (others, mut randomness, masked_signing_key_shares, masked_rs) =
9191
self.compute_randomness_and_arguments_for_multiplication::<D>(signing_key)?;
92-
debug_assert_eq!(randomness.len() as u64, 2 * batch_size);
92+
debug_assert_eq!(randomness.len() as u32, 2 * batch_size);
9393
let e = randomness.drain(0..batch_size as usize).collect();
9494
let s = randomness;
9595
Ok(Phase1Output {
@@ -248,8 +248,8 @@ pub mod tests {
248248
ote_params: MultiplicationOTEParams<KAPPA, STATISTICAL_SECURITY_PARAMETER>,
249249
threshold_signers: u16,
250250
total_signers: u16,
251-
sig_batch_size: usize,
252-
message_count: usize,
251+
sig_batch_size: u32,
252+
message_count: u32,
253253
gadget_vector: &GadgetVector<Fr, KAPPA, STATISTICAL_SECURITY_PARAMETER>,
254254
) {
255255
let protocol_id = b"test".to_vec();
@@ -351,7 +351,7 @@ pub mod tests {
351351
total_phase1_time = start.elapsed();
352352
println!("Phase 1 took {:?}", total_phase1_time);
353353

354-
assert_eq!(expected_sk, sk * Fr::from(sig_batch_size as u64));
354+
assert_eq!(expected_sk, sk * Fr::from(sig_batch_size));
355355
for i in 1..threshold_signers {
356356
assert_eq!(round1outs[0].e, round1outs[i as usize].e);
357357
assert_eq!(round1outs[0].s, round1outs[i as usize].s);

bbs_plus/src/threshold/zero_sharing.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use oblivious_transfer_protocols::ParticipantId;
2323
pub struct Party<F: PrimeField, const SALT_SIZE: usize> {
2424
pub id: ParticipantId,
2525
pub protocol_id: Vec<u8>,
26-
pub batch_size: u64,
26+
pub batch_size: u32,
2727
/// Commit-and-release coin tossing protocols run with each party
2828
pub cointoss_protocols: BTreeMap<ParticipantId, CommitmentParty<F, SALT_SIZE>>,
2929
}
@@ -36,7 +36,7 @@ impl<F: PrimeField, const SALT_SIZE: usize> Party<F, SALT_SIZE> {
3636
pub fn init<R: RngCore>(
3737
rng: &mut R,
3838
id: ParticipantId,
39-
batch_size: usize,
39+
batch_size: u32,
4040
others: BTreeSet<ParticipantId>,
4141
protocol_id: Vec<u8>,
4242
) -> (Self, BTreeMap<ParticipantId, Commitments>) {
@@ -52,7 +52,7 @@ impl<F: PrimeField, const SALT_SIZE: usize> Party<F, SALT_SIZE> {
5252
Self {
5353
id,
5454
protocol_id,
55-
batch_size: batch_size as u64,
55+
batch_size: batch_size,
5656
cointoss_protocols,
5757
},
5858
commitments,
@@ -174,7 +174,7 @@ pub mod tests {
174174
fn zero_sharing() {
175175
let mut rng = StdRng::seed_from_u64(0u64);
176176

177-
fn check(rng: &mut StdRng, batch_size: usize, num_parties: u16) {
177+
fn check(rng: &mut StdRng, batch_size: u32, num_parties: u16) {
178178
let protocol_id = b"test".to_vec();
179179
let all_party_set = (1..=num_parties).into_iter().collect::<BTreeSet<_>>();
180180
let mut parties = vec![];

0 commit comments

Comments
 (0)