Skip to content

Commit d559a0d

Browse files
committed
misc changes
1 parent a6919f8 commit d559a0d

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

gkr/src/poly_commit/orion.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ pub type OrionResult<T> = std::result::Result<T, OrionPCSError>;
2121
* IMPLEMENTATIONS FOR ORION EXPANDER GRAPH *
2222
********************************************/
2323

24-
type Edge = usize;
24+
type DiredtedEdge = usize;
2525

26-
type Neighboring = Vec<Edge>;
26+
type DirectedNeighboring = Vec<DiredtedEdge>;
2727

2828
#[derive(Clone)]
2929
pub struct OrionExpanderGraph {
@@ -37,7 +37,7 @@ pub struct OrionExpanderGraph {
3737
// of vertices in R set of the bipariate graph, which explains why it has
3838
// size of l_vertices_size, while each neighboring reserved r_vertices_size
3939
// capacity.
40-
pub neighborings: Vec<Neighboring>,
40+
pub neighborings: Vec<DirectedNeighboring>,
4141
}
4242

4343
impl OrionExpanderGraph {
@@ -47,7 +47,7 @@ impl OrionExpanderGraph {
4747
expanding_degree: usize,
4848
mut rng: impl rand::RngCore,
4949
) -> Self {
50-
let mut neighborings: Vec<Neighboring> =
50+
let mut neighborings: Vec<DirectedNeighboring> =
5151
vec![Vec::with_capacity(l_vertices_size); r_vertices_size];
5252

5353
(0..l_vertices_size).for_each(|l_index| {
@@ -90,7 +90,7 @@ impl OrionExpanderGraph {
9090
* IMPLEMENTATIONS FOR ORION CODE FROM EXPANDER GRAPH *
9191
******************************************************/
9292

93-
#[derive(Debug, Clone, Copy)]
93+
#[derive(Debug, Clone, Copy, PartialEq)]
9494
pub struct OrionCodeParameter {
9595
// empirical parameters for the expander code on input/output size
9696
// NOTE: the derived code rate and invert code rate should preserve
@@ -206,8 +206,8 @@ impl OrionCode {
206206

207207
recursive_code_msg_code_starts.push((g0_input_starts, g0_output_starts));
208208

209-
g0_input_starts = g0_output_starts;
210-
g0_output_starts += g0_output_len;
209+
(g0_input_starts, g0_output_starts) =
210+
(g0_output_starts, g0_output_starts + g0_output_len);
211211
}
212212

213213
let mut g1_output_starts = g0_output_starts;
@@ -259,3 +259,13 @@ impl OrionCode {
259259
Ok(codeword)
260260
}
261261
}
262+
263+
/**********************************************************
264+
* IMPLEMENTATIONS FOR ORION POLYNOMIAL COMMITMENT SCHEME *
265+
**********************************************************/
266+
267+
// TODO multilinear polynomial
268+
// TODO write to matrix, encode each row (k x k matrix)
269+
// TODO need a merkle tree to commit each column (k x n matrix)
270+
// - TODO need a cache friendly transpose
271+
// TODO need a merkle tree to commit against all merkle tree roots

gkr/src/poly_commit/orion_test.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,29 @@ use gf2_128::GF2_128;
55
use crate::{OrionCode, OrionCodeParameter};
66

77
fn gen_msg_codeword<F: Field>(code: &OrionCode, mut rng: impl rand::RngCore) -> (Vec<F>, Vec<F>) {
8-
let random_msg0: Vec<_> = (0..code.msg_len())
8+
let random_msg: Vec<_> = (0..code.msg_len())
99
.map(|_| F::random_unsafe(&mut rng))
1010
.collect();
1111

12-
let codeword0 = code.encode(&random_msg0).unwrap();
12+
let codeword = code.encode(&random_msg).unwrap();
1313

14-
(random_msg0, codeword0)
14+
(random_msg, codeword)
1515
}
1616

1717
fn linear_combine<F: Field>(vec_s: &Vec<Vec<F>>, scalars: &[F]) -> Vec<F> {
1818
assert_eq!(vec_s.len(), scalars.len());
1919

2020
let mut out = vec![F::ZERO; vec_s[0].len()];
2121

22-
scalars.iter().enumerate().for_each(|(i, scalar)| {
23-
vec_s[i]
24-
.iter()
25-
.zip(out.iter_mut())
26-
.for_each(|(v_ij, o_j)| *o_j += *v_ij * scalar);
27-
});
22+
scalars
23+
.iter()
24+
.zip(vec_s.iter())
25+
.for_each(|(scalar_i, vec_i)| {
26+
vec_i
27+
.iter()
28+
.zip(out.iter_mut())
29+
.for_each(|(v_ij, o_j)| *o_j += *v_ij * scalar_i);
30+
});
2831

2932
out
3033
}
@@ -38,8 +41,8 @@ fn test_orion_code_generic<F: Field>() {
3841
// This set of params might not be carefully calculated for soundness.
3942
// Only used here for testing purpose
4043
let example_orion_code_parameter = OrionCodeParameter {
41-
input_message_len: (1 << 10),
42-
output_code_len: (1 << 12),
44+
input_message_len: 1 << 10,
45+
output_code_len: 1 << 12,
4346

4447
alpha_g0: 0.5,
4548
degree_g0: 6,

0 commit comments

Comments
 (0)