Skip to content

Commit

Permalink
refactor snark
Browse files Browse the repository at this point in the history
  • Loading branch information
chancharles92 committed Nov 10, 2022
1 parent bee6768 commit bd1fc98
Show file tree
Hide file tree
Showing 8 changed files with 343 additions and 293 deletions.
4 changes: 2 additions & 2 deletions arithmetic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ mod virtual_polynomial;
pub use errors::ArithErrors;
pub use multilinear_polynomial::{
evaluate_no_par, evaluate_opt, fix_last_variables, fix_last_variables_no_par, fix_variables,
identity_permutation_mles, merge_polynomials, random_mle_list, random_permutation_mles,
random_zero_mle_list, DenseMultilinearExtension,
identity_permutation, identity_permutation_mles, merge_polynomials, random_mle_list,
random_permutation, random_permutation_mles, random_zero_mle_list, DenseMultilinearExtension,
};
pub use univariate_polynomial::{build_l, get_uni_domain};
pub use util::{bit_decompose, gen_eval_point, get_batched_nv, get_index};
Expand Down
20 changes: 17 additions & 3 deletions arithmetic/src/multilinear_polynomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ pub fn random_zero_mle_list<F: PrimeField, R: RngCore>(
list
}

pub fn identity_permutation<F: PrimeField>(num_vars: usize, num_chunks: usize) -> Vec<F> {
let len = (num_chunks as u64) * (1u64 << num_vars);
(0..len).map(F::from).collect()
}

/// A list of MLEs that represents an identity permutation
pub fn identity_permutation_mles<F: PrimeField>(
num_vars: usize,
Expand All @@ -88,19 +93,28 @@ pub fn identity_permutation_mles<F: PrimeField>(
res
}

/// A list of MLEs that represent a random permutation
pub fn random_permutation_mles<F: PrimeField, R: RngCore>(
pub fn random_permutation<F: PrimeField, R: RngCore>(
num_vars: usize,
num_chunks: usize,
rng: &mut R,
) -> Vec<Rc<DenseMultilinearExtension<F>>> {
) -> Vec<F> {
let len = (num_chunks as u64) * (1u64 << num_vars);
let mut s_id_vec: Vec<F> = (0..len).map(F::from).collect();
let mut s_perm_vec = vec![];
for _ in 0..len {
let index = rng.next_u64() as usize % s_id_vec.len();
s_perm_vec.push(s_id_vec.remove(index));
}
s_perm_vec
}

/// A list of MLEs that represent a random permutation
pub fn random_permutation_mles<F: PrimeField, R: RngCore>(
num_vars: usize,
num_chunks: usize,
rng: &mut R,
) -> Vec<Rc<DenseMultilinearExtension<F>>> {
let s_perm_vec = random_permutation(num_vars, num_chunks, rng);
let mut res = vec![];
let n = 1 << num_vars;
for i in 0..num_chunks {
Expand Down
5 changes: 2 additions & 3 deletions hyperplonk/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use arithmetic::identity_permutation_mles;
use arithmetic::identity_permutation;
use ark_ff::PrimeField;
use ark_poly::MultilinearExtension;
use ark_std::{log2, test_rng};

use crate::{
Expand Down Expand Up @@ -93,7 +92,7 @@ impl<F: PrimeField> MockCircuit<F> {
gate_func: gate.clone(),
};

let permutation = identity_permutation_mles(merged_nv as usize, 1)[0].to_evaluations();
let permutation = identity_permutation(merged_nv as usize, 1);
let index = HyperPlonkIndex {
params,
permutation,
Expand Down
Loading

0 comments on commit bd1fc98

Please sign in to comment.