Skip to content

Commit

Permalink
More replacements
Browse files Browse the repository at this point in the history
  • Loading branch information
olegnn authored and lovesh committed Sep 1, 2023
1 parent 4f8eecb commit b7c11df
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 40 deletions.
2 changes: 1 addition & 1 deletion bbs_plus/src/threshold/threshold_bbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl<E: Pairing> BBSSignatureShare<E> {
&phase1.e[sig_index_in_batch],
&phase1.masked_rs[sig_index_in_batch],
&phase1.masked_signing_key_shares[sig_index_in_batch],
sig_index_in_batch,
sig_index_in_batch as u32,
phase2,
);
Ok(Self {
Expand Down
2 changes: 1 addition & 1 deletion bbs_plus/src/threshold/threshold_bbs_plus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl<E: Pairing> BBSPlusSignatureShare<E> {
&phase1.e[sig_index_in_batch],
&phase1.masked_rs[sig_index_in_batch],
&phase1.masked_signing_key_shares[sig_index_in_batch],
sig_index_in_batch,
sig_index_in_batch as u32,
phase2,
);
Ok(Self {
Expand Down
10 changes: 5 additions & 5 deletions bbs_plus/src/threshold/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ pub fn compute_R_and_u<G: AffineRepr>(
e: &G::ScalarField,
masked_r: &G::ScalarField,
masked_signing_key_share: &G::ScalarField,
index_in_output: usize,
index_in_output: u32,
phase2: &Phase2Output<G::ScalarField>,
) -> (G, G::ScalarField) {
let R = base.mul(r).into_affine();
let mut u = *masked_r * (*e + masked_signing_key_share);
for (_, (a, b)) in &phase2.z_A {
u += a[index_in_output];
u += b[index_in_output];
u += a[index_in_output as usize];
u += b[index_in_output as usize];
}
for (_, (a, b)) in &phase2.z_B {
u += a[index_in_output];
u += b[index_in_output];
u += a[index_in_output as usize];
u += b[index_in_output as usize];
}
(R, u)
}
8 changes: 4 additions & 4 deletions legogroth16/src/aggregation/srs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,10 @@ pub fn setup_fake_srs<E: Pairing, R: Rng>(rng: &mut R, size: u32) -> GenericSRS<

#[cfg(not(feature = "parallel"))]
{
g_alpha_powers = structured_generators_scalar_power(2 * size, &g, &alpha);
g_beta_powers = structured_generators_scalar_power(2 * size, &g, &beta);
h_alpha_powers = structured_generators_scalar_power(2 * size, &h, &alpha);
h_beta_powers = structured_generators_scalar_power(2 * size, &h, &beta);
g_alpha_powers = structured_generators_scalar_power(2 * size as usize, &g, &alpha);
g_beta_powers = structured_generators_scalar_power(2 * size as usize, &g, &beta);
h_alpha_powers = structured_generators_scalar_power(2 * size as usize, &h, &alpha);
h_beta_powers = structured_generators_scalar_power(2 * size as usize, &h, &beta);
}

debug_assert!(h_alpha_powers[0] == E::G2Affine::generator());
Expand Down
6 changes: 3 additions & 3 deletions oblivious_transfer/src/base_ot/simplest_ot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl<G: AffineRepr> ROTSenderSetup<G> {
} else {
(yR[i] - jT[j - 1]).into_affine()
};
hash_to_otp::<G, KEY_SIZE>(i, &self.S, &R.0[i], &jt)
hash_to_otp::<G, KEY_SIZE>(i as u32, &self.S, &R.0[i], &jt)
})
.collect::<Vec<_>>()
})
Expand Down Expand Up @@ -268,7 +268,7 @@ impl ROTReceiverKeys {
}
let keys = cfg_iter!(xS)
.enumerate()
.map(|(i, xs)| hash_to_otp::<G, KEY_SIZE>(i, &S.0, &R[i], xs))
.map(|(i, xs)| hash_to_otp::<G, KEY_SIZE>(i as u32, &S.0, &R[i], xs))
.collect::<Vec<_>>();
Ok((Self(keys), ReceiverPubKeys(R)))
}
Expand Down Expand Up @@ -485,7 +485,7 @@ impl OneOfTwoROTSenderKeys {

// TODO: Make it use const generic for key size and generic digest
pub fn hash_to_otp<G: CanonicalSerialize, const KEY_SIZE: u16>(
index: usize,
index: u32,
s: &G,
r: &G,
input: &G,
Expand Down
20 changes: 10 additions & 10 deletions oblivious_transfer/src/ot_extensions/alsz_ote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl OTExtensionReceiverSetup {
cfg_into_iter!(0..self.ote_config.num_ot_extensions as usize)
.map(|i| {
let t = &self.T.0[i * row_byte_size..(i + 1) * row_byte_size as usize];
hash_to_otp(i, &t, message_size)
hash_to_otp(i as u32, &t, message_size)
})
.collect()
}
Expand All @@ -278,7 +278,7 @@ impl OTExtensionReceiverSetup {
let t = &T.0[i * row_byte_size..(i + 1) * row_byte_size];
xor(
if !ot_extension_choices[i] { &e1 } else { &e2 },
&hash_to_otp(i, &t, message_size),
&hash_to_otp(i as u32, &t, message_size),
)
})
.collect())
Expand All @@ -305,7 +305,7 @@ impl OTExtensionReceiverSetup {
let t = &T.0[i * row_byte_size..(i + 1) * row_byte_size];
xor(
if !ot_extension_choices[i] { &zero } else { &e },
&hash_to_otp(i, &t, message_size),
&hash_to_otp(i as u32, &t, message_size),
)
})
.collect())
Expand Down Expand Up @@ -574,8 +574,8 @@ impl OTExtensionSenderSetup {
cfg_into_iter!(0..self.ote_config.num_ot_extensions as usize)
.map(|i| {
let q = &self.Q.0[i * row_byte_size..(i + 1) * row_byte_size];
let x1 = hash_to_otp(i, &q, message_size);
let x2 = hash_to_otp(i, &xor(&q, &self.base_ot_choices), message_size);
let x1 = hash_to_otp(i as u32, &q, message_size);
let x2 = hash_to_otp(i as u32, &xor(&q, &self.base_ot_choices), message_size);
(x1, x2)
})
.collect()
Expand All @@ -599,10 +599,10 @@ impl OTExtensionSenderSetup {
.enumerate()
.map(|(i, (m1, m2))| {
let q = &Q.0[i * row_byte_size..(i + 1) * row_byte_size];
let e1 = xor(&m1, &hash_to_otp(i, &q, message_size));
let e1 = xor(&m1, &hash_to_otp(i as u32, &q, message_size));
let e2 = xor(
&m2,
&hash_to_otp(i, &xor(&q, base_ot_choices), message_size),
&hash_to_otp(i as u32, &xor(&q, base_ot_choices), message_size),
);
(e1, e2)
})
Expand All @@ -627,9 +627,9 @@ impl OTExtensionSenderSetup {
.enumerate()
.map(|(i, delta)| {
let q = &Q.0[i * row_byte_size..(i + 1) * row_byte_size];
let x1 = hash_to_otp(i, &q, message_size);
let x1 = hash_to_otp(i as u32, &q, message_size);
let x2 = delta(&x1);
let e = xor(&x2, &hash_to_otp(i, &xor(&q, &s), message_size));
let e = xor(&x2, &hash_to_otp(i as u32, &xor(&q, &s), message_size));
((x1, x2), e)
})
.collect::<Vec<_>>()
Expand Down Expand Up @@ -706,7 +706,7 @@ fn key_to_aes_rng(key: &Key) -> AesRng {
}

/// Create a one time pad of required size
fn hash_to_otp(index: usize, q: &[u8], pad_size: u32) -> Vec<u8> {
fn hash_to_otp(index: u32, q: &[u8], pad_size: u32) -> Vec<u8> {
let mut bytes = index.to_be_bytes().to_vec();
bytes.extend_from_slice(q);
let mut pad = vec![0; pad_size as usize];
Expand Down
8 changes: 4 additions & 4 deletions oblivious_transfer/src/ot_extensions/kos_ote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl OTExtensionReceiverSetup {
F::zero()
};
let tau_i = (tau_i.0 * m, tau_i.1 * m);
let mut t_B_i = hash_to_field(i, &t, &hasher);
let mut t_B_i = hash_to_field(i as u32, &t, &hasher);
t_B_i = (tau_i.0 - t_B_i.0, tau_i.1 - t_B_i.1);
t_B_i
})
Expand Down Expand Up @@ -325,8 +325,8 @@ impl OTExtensionSenderSetup {
.map(|(i, alpha_i)| {
let hasher = <DefaultFieldHasher<D> as HashToField<F>>::new(b"KOS-OTE");
let q = &self.Q.0[i * row_byte_size..(i + 1) * row_byte_size];
let t_A_i = hash_to_field(i, &q, &hasher);
let mut tau_i = hash_to_field(i, &xor(&q, &self.base_ot_choices), &hasher);
let t_A_i = hash_to_field(i as u32, &q, &hasher);
let mut tau_i = hash_to_field(i as u32, &xor(&q, &self.base_ot_choices), &hasher);
tau_i = (tau_i.0 - t_A_i.0 + alpha_i.0, tau_i.1 - t_A_i.1 + alpha_i.1);
(t_A_i, tau_i)
})
Expand Down Expand Up @@ -367,7 +367,7 @@ fn gen_randomness(a: u32, b: u32, U: &BitMatrix, output_size: u32) -> Vec<u8> {
}

pub fn hash_to_field<F: PrimeField, D: Default + DynDigest + Clone>(
index: usize,
index: u32,
q: &[u8],
hasher: &DefaultFieldHasher<D>,
) -> (F, F) {
Expand Down
15 changes: 7 additions & 8 deletions proof_system/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,20 +334,19 @@ impl<E: Pairing> R1CSCircomWitness<E> {
&self,
n: u32,
) -> Result<Vec<E::ScalarField>, ProofSystemError> {
let n = n as usize;
if self.private_count < n {
if self.private_count < n as usize {
return Err(ProofSystemError::R1CSInsufficientPrivateInputs(
self.private_count,
n,
self.private_count as usize,
n as usize,
));
}
let mut inputs = Vec::with_capacity(n);
let mut inputs = Vec::with_capacity(n as usize);
for name in self.private.iter() {
if n == inputs.len() {
if n as usize == inputs.len() {
break;
}
let vals = self.inputs.get(name).unwrap();
let m = cmp::min(n - inputs.len(), vals.len());
let m = cmp::min(n as usize - inputs.len(), vals.len());
inputs.extend_from_slice(&vals[0..m]);
}
Ok(inputs)
Expand Down Expand Up @@ -419,7 +418,7 @@ mod tests {

#[test]
fn witness_serialization_deserialization() {
let mut rng = StdRng::seed_from_u64(0u64);
let mut rng = StdRng::seed_from_u64(0);
let (msgs, _, _, sig) = bbs_plus_sig_setup(&mut rng, 5);
let (msgs_23, _, _, sig_23) = bbs_sig_setup(&mut rng, 5);

Expand Down
4 changes: 2 additions & 2 deletions saver/src/encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ pub(crate) mod tests {

pub fn gen_messages<R: RngCore>(
rng: &mut R,
count: usize,
count: u32,
chunk_bit_size: u8,
) -> Vec<CHUNK_TYPE> {
(0..count)
Expand All @@ -822,7 +822,7 @@ pub(crate) mod tests {
fn encrypt_decrypt() {
fn check(chunk_bit_size: u8) {
let mut rng = StdRng::seed_from_u64(0u64);
let n = chunks_count::<Fr>(chunk_bit_size) as usize;
let n = chunks_count::<Fr>(chunk_bit_size) as u32;
// Get random numbers that are of chunk_bit_size at most
let m = gen_messages(&mut rng, n, chunk_bit_size);
let (gens, g_i, sk, ek, dk) = enc_setup(chunk_bit_size, &mut rng);
Expand Down
2 changes: 1 addition & 1 deletion saver/src/saver_groth16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ mod tests {
let gens = EncryptionGens::<Bls12_381>::new_using_rng(&mut rng);
let n = chunks_count::<Fr>(chunk_bit_size);
// Get random numbers that are of chunk_bit_size at most
let msgs = gen_messages(&mut rng, n as usize, chunk_bit_size);
let msgs = gen_messages(&mut rng, n as u32, chunk_bit_size);
let msgs_as_field_elems = msgs.iter().map(|m| Fr::from(*m as u64)).collect::<Vec<_>>();

let circuit = BitsizeCheckCircuit::new(chunk_bit_size, Some(n), None, true);
Expand Down
2 changes: 1 addition & 1 deletion saver/src/saver_legogroth16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ mod tests {
let gens = EncryptionGens::<Bls12_381>::new_using_rng(&mut rng);

// Get random numbers that are of chunk_bit_size at most
let msgs = gen_messages(&mut rng, n as usize, chunk_bit_size);
let msgs = gen_messages(&mut rng, n as u32, chunk_bit_size);
let msgs_as_field_elems = msgs.iter().map(|m| Fr::from(*m as u64)).collect::<Vec<_>>();

let circuit = BitsizeCheckCircuit::new(chunk_bit_size, Some(n), None, false);
Expand Down

0 comments on commit b7c11df

Please sign in to comment.