Skip to content

Commit a6919f8

Browse files
committed
unweighted graph, use only additions in the codeword generation
1 parent 2cd3efe commit a6919f8

File tree

2 files changed

+31
-48
lines changed

2 files changed

+31
-48
lines changed

gkr/src/poly_commit/orion.rs

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

24-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
25-
pub struct WeightedEdge<F: Field> {
26-
pub index: usize,
27-
pub weight: F,
28-
}
29-
30-
impl<F: Field> WeightedEdge<F> {
31-
#[inline(always)]
32-
pub fn new(index: usize, mut rng: impl rand::RngCore) -> Self {
33-
Self {
34-
index,
35-
weight: F::random_unsafe(&mut rng),
36-
}
37-
}
38-
}
24+
type Edge = usize;
3925

40-
type Neighboring<F> = Vec<WeightedEdge<F>>;
26+
type Neighboring = Vec<Edge>;
4127

4228
#[derive(Clone)]
43-
pub struct OrionExpanderGraph<F: Field> {
29+
pub struct OrionExpanderGraph {
4430
// L R vertices size book keeping:
4531
// keep track of message length (l), and "compressed" code length (r)
4632
pub l_vertices_size: usize,
4733
pub r_vertices_size: usize,
4834

4935
// neighboring stands for all (weighted) connected vertices of a vertex.
50-
// In this context, the weighted_neighborings stands for the neighborings
36+
// In this context, the neighborings stands for the neighborings
5137
// of vertices in R set of the bipariate graph, which explains why it has
5238
// size of l_vertices_size, while each neighboring reserved r_vertices_size
5339
// capacity.
54-
pub weighted_neighborings: Vec<Neighboring<F>>,
40+
pub neighborings: Vec<Neighboring>,
5541
}
5642

57-
impl<F: Field> OrionExpanderGraph<F> {
43+
impl OrionExpanderGraph {
5844
pub fn new(
5945
l_vertices_size: usize,
6046
r_vertices_size: usize,
6147
expanding_degree: usize,
6248
mut rng: impl rand::RngCore,
6349
) -> Self {
64-
let mut weighted_neighborings: Vec<Neighboring<F>> =
50+
let mut neighborings: Vec<Neighboring> =
6551
vec![Vec::with_capacity(l_vertices_size); r_vertices_size];
6652

6753
(0..l_vertices_size).for_each(|l_index| {
6854
let random_r_vertices = index::sample(&mut rng, r_vertices_size, expanding_degree);
6955

70-
random_r_vertices.iter().for_each(|r_index| {
71-
weighted_neighborings[r_index].push(WeightedEdge::new(l_index, &mut rng))
72-
})
56+
random_r_vertices
57+
.iter()
58+
.for_each(|r_index| neighborings[r_index].push(l_index))
7359
});
7460

7561
Self {
76-
weighted_neighborings,
62+
neighborings,
7763
l_vertices_size,
7864
r_vertices_size,
7965
}
8066
}
8167

8268
#[inline(always)]
83-
pub fn expander_mul(&self, l_vertices: &[F], r_vertices: &mut [F]) -> OrionResult<()> {
69+
pub fn expander_mul<F: Field>(
70+
&self,
71+
l_vertices: &[F],
72+
r_vertices: &mut [F],
73+
) -> OrionResult<()> {
8474
if l_vertices.len() != self.l_vertices_size || r_vertices.len() != self.r_vertices_size {
8575
return Err(OrionPCSError::ParameterUnmatchError);
8676
}
8777

8878
r_vertices
8979
.iter_mut()
90-
.zip(self.weighted_neighborings.iter())
80+
.zip(self.neighborings.iter())
9181
.for_each(|(ri, ni)| {
92-
*ri = ni
93-
.iter()
94-
.map(|WeightedEdge { index, weight }| l_vertices[*index] * weight)
95-
.sum();
82+
*ri = ni.iter().map(|&edge_i| l_vertices[edge_i]).sum();
9683
});
9784

9885
Ok(())
@@ -139,15 +126,15 @@ impl OrionCodeParameter {
139126
}
140127

141128
#[derive(Clone)]
142-
pub struct OrionExpanderGraphPositioned<F: Field> {
143-
pub graph: OrionExpanderGraph<F>,
129+
pub struct OrionExpanderGraphPositioned {
130+
pub graph: OrionExpanderGraph,
144131

145132
pub input_starts: usize,
146133
pub output_starts: usize,
147134
pub output_ends: usize,
148135
}
149136

150-
impl<F: Field> OrionExpanderGraphPositioned<F> {
137+
impl OrionExpanderGraphPositioned {
151138
#[inline(always)]
152139
pub fn new(
153140
input_starts: usize,
@@ -170,7 +157,7 @@ impl<F: Field> OrionExpanderGraphPositioned<F> {
170157
}
171158

172159
#[inline(always)]
173-
pub fn expander_mul(&self, buffer: &mut [F], scratch: &mut [F]) -> OrionResult<()> {
160+
pub fn expander_mul<F: Field>(&self, buffer: &mut [F], scratch: &mut [F]) -> OrionResult<()> {
174161
let input_ref = &buffer[self.input_starts..self.output_starts];
175162
let output_ref = &mut scratch[self.output_starts..self.output_ends + 1];
176163

@@ -183,24 +170,24 @@ impl<F: Field> OrionExpanderGraphPositioned<F> {
183170

184171
// TODO: Orion code ascii code explanation for g0s and g1s, how they encode msg
185172
#[derive(Clone)]
186-
pub struct OrionCode<F: Field> {
173+
pub struct OrionCode {
187174
pub params: OrionCodeParameter,
188175

189176
// g0s (affecting left side alphabets of the codeword)
190177
// generated from the largest to the smallest
191-
pub g0s: Vec<OrionExpanderGraphPositioned<F>>,
178+
pub g0s: Vec<OrionExpanderGraphPositioned>,
192179

193180
// g1s (affecting right side alphabets of the codeword)
194181
// generated from the smallest to the largest
195-
pub g1s: Vec<OrionExpanderGraphPositioned<F>>,
182+
pub g1s: Vec<OrionExpanderGraphPositioned>,
196183
}
197184

198-
impl<F: Field> OrionCode<F> {
185+
impl OrionCode {
199186
pub fn new(params: OrionCodeParameter, mut rng: impl rand::RngCore) -> Self {
200187
let mut recursive_code_msg_code_starts: Vec<(usize, usize)> = Vec::new();
201188

202-
let mut g0s: Vec<OrionExpanderGraphPositioned<F>> = Vec::new();
203-
let mut g1s: Vec<OrionExpanderGraphPositioned<F>> = Vec::new();
189+
let mut g0s: Vec<OrionExpanderGraphPositioned> = Vec::new();
190+
let mut g1s: Vec<OrionExpanderGraphPositioned> = Vec::new();
204191

205192
let mut g0_input_starts = 0;
206193
let mut g0_output_starts = params.input_message_len;
@@ -254,7 +241,7 @@ impl<F: Field> OrionCode<F> {
254241
}
255242

256243
#[inline(always)]
257-
pub fn encode(&self, msg: &[F]) -> OrionResult<Vec<F>> {
244+
pub fn encode<F: Field>(&self, msg: &[F]) -> OrionResult<Vec<F>> {
258245
if msg.len() != self.msg_len() {
259246
return Err(OrionPCSError::ParameterUnmatchError);
260247
}

gkr/src/poly_commit/orion_test.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ use gf2_128::GF2_128;
44

55
use crate::{OrionCode, OrionCodeParameter};
66

7-
fn gen_msg_codeword<F: Field>(
8-
code: &OrionCode<F>,
9-
mut rng: impl rand::RngCore,
10-
) -> (Vec<F>, Vec<F>) {
7+
fn gen_msg_codeword<F: Field>(code: &OrionCode, mut rng: impl rand::RngCore) -> (Vec<F>, Vec<F>) {
118
let random_msg0: Vec<_> = (0..code.msg_len())
129
.map(|_| F::random_unsafe(&mut rng))
1310
.collect();
@@ -52,9 +49,8 @@ fn test_orion_code_generic<F: Field>() {
5249
degree_g1: 6,
5350
};
5451

55-
let orion_code = OrionCode::<F>::new(example_orion_code_parameter, &mut rng);
52+
let orion_code = OrionCode::new(example_orion_code_parameter, &mut rng);
5653

57-
// TODO: 128 scalars
5854
let linear_combine_size = 128;
5955

6056
let random_scalrs: Vec<_> = (0..linear_combine_size)

0 commit comments

Comments
 (0)