Skip to content

Commit 6aae916

Browse files
committed
Normalize the runtime table configuration to "custom"
Previously, we were considering two types of runtime table configurations, indexed and custom. Indexed where supposed to represent "standard" array access, using indexed from 0 to N, which can be easily represented as a "custom" runtime table configurations whose first columns is from 0 to N. It also simplifies the wasm binding as enum with structure values can not be represented using wasm-bindgen.
1 parent 5d2a4c6 commit 6aae916

File tree

3 files changed

+21
-60
lines changed

3 files changed

+21
-60
lines changed

kimchi/src/circuits/lookup/index.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,14 +269,8 @@ impl<F: PrimeField + SquareRootField> LookupConstraintSystem<F> {
269269

270270
// create fixed tables for indexing the runtime tables
271271
for runtime_table in runtime_tables {
272-
use RuntimeTableCfg::{Custom, Indexed};
273-
let (id, first_column) = match runtime_table {
274-
&Indexed(RuntimeTableSpec { id, len }) => {
275-
let indexes = (0..(len as u32)).map(F::from).collect();
276-
(id, indexes)
277-
}
278-
Custom { id, first_column } => (*id, first_column.clone()),
279-
};
272+
let (id, first_column) =
273+
(runtime_table.id, runtime_table.first_column.clone());
280274

281275
// record if table ID 0 is used in one of the runtime tables
282276
// note: the check later will still force you to have a fixed table with ID 0

kimchi/src/circuits/lookup/runtime_tables.rs

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,56 +22,35 @@ pub struct RuntimeTableSpec {
2222
///
2323
/// Note: care must be taken as table IDs can collide with IDs of other types of lookup tables.
2424
#[derive(Debug, Clone, Serialize, Deserialize)]
25-
pub enum RuntimeTableCfg<F> {
26-
/// An indexed runtime table has a counter (starting at zero) in its first column.
27-
Indexed(RuntimeTableSpec),
28-
/// A custom runtime table can contain arbitrary values in its first column.
29-
Custom {
30-
/// The table ID.
31-
id: i32,
32-
/// The content of the first column of the runtime table.
33-
first_column: Vec<F>,
34-
},
25+
pub struct RuntimeTableCfg<F> {
26+
/// The table ID.
27+
pub id: i32,
28+
/// The content of the first column of the runtime table.
29+
pub first_column: Vec<F>,
3530
}
3631

3732
impl<F> RuntimeTableCfg<F> {
3833
/// Returns the ID of the runtime table.
3934
pub fn id(&self) -> i32 {
40-
use RuntimeTableCfg::{Custom, Indexed};
41-
match self {
42-
Indexed(cfg) => cfg.id,
43-
&Custom { id, .. } => id,
44-
}
35+
self.id
4536
}
4637

4738
/// Returns the length of the runtime table.
4839
pub fn len(&self) -> usize {
49-
use RuntimeTableCfg::{Custom, Indexed};
50-
match self {
51-
Indexed(cfg) => cfg.len,
52-
Custom { first_column, .. } => first_column.len(),
53-
}
40+
self.first_column.len()
5441
}
5542

5643
/// Returns `true` if the runtime table is empty.
5744
pub fn is_empty(&self) -> bool {
58-
use RuntimeTableCfg::{Custom, Indexed};
59-
match self {
60-
Indexed(cfg) => cfg.len == 0,
61-
Custom { first_column, .. } => first_column.is_empty(),
62-
}
45+
self.first_column.is_empty()
6346
}
6447
}
6548

6649
impl<F> From<RuntimeTableCfg<F>> for RuntimeTableSpec {
67-
fn from(from: RuntimeTableCfg<F>) -> Self {
68-
use RuntimeTableCfg::{Custom, Indexed};
69-
match from {
70-
Indexed(cfg) => cfg,
71-
Custom { id, first_column } => RuntimeTableSpec {
72-
id,
73-
len: first_column.len(),
74-
},
50+
fn from(rt_cfg: RuntimeTableCfg<F>) -> Self {
51+
Self {
52+
id: rt_cfg.id,
53+
len: rt_cfg.first_column.len(),
7554
}
7655
}
7756
}

kimchi/src/tests/lookup.rs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::framework::{print_witness, TestFramework};
22
use crate::circuits::{
33
gate::{CircuitGate, GateType},
44
lookup::{
5-
runtime_tables::{RuntimeTable, RuntimeTableCfg, RuntimeTableSpec},
5+
runtime_tables::{RuntimeTable, RuntimeTableCfg},
66
tables::LookupTable,
77
},
88
polynomial::COLUMNS,
@@ -125,20 +125,13 @@ fn lookup_gate_rejects_bad_lookups_multiple_tables() {
125125
setup_lookup_proof(false, 500, vec![100, 50, 50, 2, 2])
126126
}
127127

128-
fn runtime_table(num: usize, indexed: bool) {
128+
fn runtime_table(num: usize) {
129129
// runtime
130130
let mut runtime_tables_setup = vec![];
131131
for table_id in 0..num {
132-
let cfg = if indexed {
133-
RuntimeTableCfg::Indexed(RuntimeTableSpec {
134-
id: table_id as i32,
135-
len: 5,
136-
})
137-
} else {
138-
RuntimeTableCfg::Custom {
139-
id: table_id as i32,
140-
first_column: [8u32, 9, 8, 7, 1].into_iter().map(Into::into).collect(),
141-
}
132+
let cfg = RuntimeTableCfg {
133+
id: table_id as i32,
134+
first_column: [8u32, 9, 8, 7, 1].into_iter().map(Into::into).collect(),
142135
};
143136
runtime_tables_setup.push(cfg);
144137
}
@@ -176,7 +169,7 @@ fn runtime_table(num: usize, indexed: bool) {
176169
// create queries into our runtime lookup table
177170
let lookup_cols = &mut lookup_cols[1..];
178171
for chunk in lookup_cols.chunks_mut(2) {
179-
chunk[0][row] = if indexed { 1u32.into() } else { 9u32.into() }; // index
172+
chunk[0][row] = 9u32.into(); // index
180173
chunk[1][row] = 2u32.into(); // value
181174
}
182175
}
@@ -196,14 +189,9 @@ fn runtime_table(num: usize, indexed: bool) {
196189
.unwrap();
197190
}
198191

199-
#[test]
200-
fn test_indexed_runtime_table() {
201-
runtime_table(5, true);
202-
}
203-
204192
#[test]
205193
fn test_custom_runtime_table() {
206-
runtime_table(5, false);
194+
runtime_table(5);
207195
}
208196

209197
// TODO: add a test with a runtime table with ID 0 (it should panic)

0 commit comments

Comments
 (0)