Skip to content

Commit

Permalink
Merge pull request #2191 from AleoHQ/correctly_sample_rand_vecs
Browse files Browse the repository at this point in the history
[NCC THN] Correctly sample random vectors
  • Loading branch information
howardwu authored Nov 24, 2023
2 parents 8edd368 + 8616491 commit 9f956e1
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 11 deletions.
6 changes: 3 additions & 3 deletions algorithms/src/snark/varuna/data_structures/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,9 @@ mod test {
fn rand_evaluations<F: PrimeField>(rng: &mut TestRng, i: usize) -> Evaluations<F> {
Evaluations {
g_1_eval: F::rand(rng),
g_a_evals: vec![F::rand(rng); i],
g_b_evals: vec![F::rand(rng); i],
g_c_evals: vec![F::rand(rng); i],
g_a_evals: (0..i).map(|_| F::rand(rng)).collect(),
g_b_evals: (0..i).map(|_| F::rand(rng)).collect(),
g_c_evals: (0..i).map(|_| F::rand(rng)).collect(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion algorithms/src/snark/varuna/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ mod varuna {
for instance_input in vks_to_inputs.values() {
let mut fake_instance_input = Vec::with_capacity(instance_input.len());
for input in instance_input.iter() {
let fake_input = vec![Fr::rand(rng); input.len()];
let fake_input: Vec<_> = (0..input.len()).map(|_| Fr::rand(rng)).collect();
fake_instance_input.push(fake_input);
}
fake_instance_inputs.push(fake_instance_input);
Expand Down
6 changes: 3 additions & 3 deletions console/algorithms/benches/poseidon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn poseidon2(c: &mut Criterion) {
c.bench_function("Poseidon2 Hash 4 -> 1", |b| b.iter(|| hash.hash(&input)));
c.bench_function("Poseidon2 Hash 4 -> 2", |b| b.iter(|| hash.hash_many(&input, 2)));

let input = [F::rand(rng); 10];
let input: Vec<_> = (0..10).map(|_| F::rand(rng)).collect();
c.bench_function("Poseidon2 Hash 10 -> 1", |b| b.iter(|| hash.hash(&input)));
c.bench_function("Poseidon2 Hash 10 -> 4", |b| b.iter(|| hash.hash_many(&input, 4)));
c.bench_function("Poseidon2 Hash 10 -> 8", |b| b.iter(|| hash.hash_many(&input, 8)));
Expand All @@ -44,7 +44,7 @@ fn poseidon4(c: &mut Criterion) {
c.bench_function("Poseidon4 Hash 4 -> 1", |b| b.iter(|| hash.hash(&input)));
c.bench_function("Poseidon4 Hash 4 -> 2", |b| b.iter(|| hash.hash_many(&input, 2)));

let input = [F::rand(rng); 10];
let input: Vec<_> = (0..10).map(|_| F::rand(rng)).collect();
c.bench_function("Poseidon4 Hash 10 -> 1", |b| b.iter(|| hash.hash(&input)));
c.bench_function("Poseidon4 Hash 10 -> 4", |b| b.iter(|| hash.hash_many(&input, 4)));
c.bench_function("Poseidon4 Hash 10 -> 8", |b| b.iter(|| hash.hash_many(&input, 8)));
Expand All @@ -58,7 +58,7 @@ fn poseidon8(c: &mut Criterion) {
c.bench_function("Poseidon8 Hash 4 -> 1", |b| b.iter(|| hash.hash(&input)));
c.bench_function("Poseidon8 Hash 4 -> 2", |b| b.iter(|| hash.hash_many(&input, 2)));

let input = [F::rand(rng); 10];
let input: Vec<_> = (0..10).map(|_| F::rand(rng)).collect();
c.bench_function("Poseidon8 Hash 10 -> 1", |b| b.iter(|| hash.hash(&input)));
c.bench_function("Poseidon8 Hash 10 -> 4", |b| b.iter(|| hash.hash_many(&input, 4)));
c.bench_function("Poseidon8 Hash 10 -> 8", |b| b.iter(|| hash.hash_many(&input, 8)));
Expand Down
3 changes: 2 additions & 1 deletion ledger/block/src/transition/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ pub(crate) mod test_helpers {
let plaintext = Plaintext::Literal(Literal::Field(Uniform::rand(rng)), Default::default());
let plaintext_hash = CurrentNetwork::hash_bhp1024(&plaintext.to_bits_le()).unwrap();
// Sample a random ciphertext.
let ciphertext = Ciphertext::from_fields(&vec![Uniform::rand(rng); 10]).unwrap();
let fields: Vec<_> = (0..10).map(|_| Uniform::rand(rng)).collect();
let ciphertext = Ciphertext::from_fields(&fields).unwrap();
let ciphertext_hash = CurrentNetwork::hash_bhp1024(&ciphertext.to_bits_le()).unwrap();

vec![
Expand Down
3 changes: 2 additions & 1 deletion ledger/block/src/transition/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ pub(crate) mod test_helpers {
let plaintext = Plaintext::Literal(Literal::Field(Uniform::rand(rng)), Default::default());
let plaintext_hash = CurrentNetwork::hash_bhp1024(&plaintext.to_bits_le()).unwrap();
// Sample a random ciphertext.
let ciphertext = Ciphertext::from_fields(&vec![Uniform::rand(rng); 10]).unwrap();
let fields: Vec<_> = (0..10).map(|_| Uniform::rand(rng)).collect();
let ciphertext = Ciphertext::from_fields(&fields).unwrap();
let ciphertext_hash = CurrentNetwork::hash_bhp1024(&ciphertext.to_bits_le()).unwrap();
// Sample a random record.
let randomizer = Uniform::rand(rng);
Expand Down
6 changes: 4 additions & 2 deletions ledger/test-helpers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ pub fn sample_inputs() -> Vec<(<CurrentNetwork as Network>::TransitionID, Input<
let plaintext = Plaintext::Literal(Literal::Field(Uniform::rand(rng)), Default::default());
let plaintext_hash = CurrentNetwork::hash_bhp1024(&plaintext.to_bits_le()).unwrap();
// Sample a random ciphertext.
let ciphertext = Ciphertext::from_fields(&vec![Uniform::rand(rng); 10]).unwrap();
let fields: Vec<_> = (0..10).map(|_| Uniform::rand(rng)).collect();
let ciphertext = Ciphertext::from_fields(&fields).unwrap();
let ciphertext_hash = CurrentNetwork::hash_bhp1024(&ciphertext.to_bits_le()).unwrap();

vec![
Expand Down Expand Up @@ -97,7 +98,8 @@ pub fn sample_outputs() -> Vec<(<CurrentNetwork as Network>::TransitionID, Outpu
let plaintext = Plaintext::Literal(Literal::Field(Uniform::rand(rng)), Default::default());
let plaintext_hash = CurrentNetwork::hash_bhp1024(&plaintext.to_bits_le()).unwrap();
// Sample a random ciphertext.
let ciphertext = Ciphertext::from_fields(&vec![Uniform::rand(rng); 10]).unwrap();
let fields: Vec<_> = (0..10).map(|_| Uniform::rand(rng)).collect();
let ciphertext = Ciphertext::from_fields(&fields).unwrap();
let ciphertext_hash = CurrentNetwork::hash_bhp1024(&ciphertext.to_bits_le()).unwrap();
// Sample a random record.
let randomizer = Uniform::rand(rng);
Expand Down

0 comments on commit 9f956e1

Please sign in to comment.