Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

Commit 44000e5

Browse files
authored
[chore] Expose keccak circuit config (#519)
* expose keccak circuit APIs * expose more fields * [chore] fix clippy
1 parent 6c9df1a commit 44000e5

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

zkevm-circuits/src/keccak_circuit.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use crate::{
3838
use eth_types::Field;
3939
use gadgets::util::{and, not, select, sum, Expr};
4040
use halo2_proofs::{
41-
circuit::{Layouter, Region, Value},
41+
circuit::{AssignedCell, Layouter, Region, Value},
4242
plonk::{Column, ConstraintSystem, Error, Expression, Fixed, TableColumn, VirtualCells},
4343
poly::Rotation,
4444
};
@@ -55,7 +55,8 @@ pub struct KeccakCircuitConfig<F> {
5555
q_padding_last: Column<Fixed>,
5656
/// The columns for other circuits to lookup Keccak hash results
5757
pub keccak_table: KeccakTable,
58-
cell_manager: CellManager<F>,
58+
/// Expose the columns that stores the cells for hash input/output
59+
pub cell_manager: CellManager<F>,
5960
round_cst: Column<Fixed>,
6061
normalize_3: [TableColumn; 2],
6162
normalize_4: [TableColumn; 2],
@@ -890,12 +891,13 @@ impl<F: Field> KeccakCircuitConfig<F> {
890891
)
891892
}
892893

893-
fn set_row(
894+
/// Set the cells for a keccak row; return the cells that are assigned.
895+
pub fn set_row(
894896
&self,
895897
region: &mut Region<'_, F>,
896898
offset: usize,
897899
row: &KeccakRow<F>,
898-
) -> Result<(), Error> {
900+
) -> Result<Vec<AssignedCell<F, F>>, Error> {
899901
// Fixed selectors
900902
for (name, column, value) in &[
901903
("q_enable", self.q_enable, F::from(row.q_enable)),
@@ -930,18 +932,19 @@ impl<F: Field> KeccakCircuitConfig<F> {
930932
)?;
931933

932934
// Cell values
935+
let mut res = vec![];
933936
for (idx, (bit, column)) in row
934937
.cell_values
935938
.iter()
936939
.zip(self.cell_manager.columns())
937940
.enumerate()
938941
{
939-
region.assign_advice(
942+
res.push(region.assign_advice(
940943
|| format!("assign lookup value {} {}", idx, offset),
941944
column.advice,
942945
offset,
943946
|| Value::known(*bit),
944-
)?;
947+
)?);
945948
}
946949

947950
// Round constant
@@ -952,10 +955,11 @@ impl<F: Field> KeccakCircuitConfig<F> {
952955
|| Value::known(row.round_cst),
953956
)?;
954957

955-
Ok(())
958+
Ok(res)
956959
}
957960

958-
pub(crate) fn load_aux_tables(&self, layouter: &mut impl Layouter<F>) -> Result<(), Error> {
961+
/// Load the auxiliary table for keccak table.
962+
pub fn load_aux_tables(&self, layouter: &mut impl Layouter<F>) -> Result<(), Error> {
959963
load_normalize_table(layouter, "normalize_6", &self.normalize_6, 6u64)?;
960964
load_normalize_table(layouter, "normalize_4", &self.normalize_4, 4u64)?;
961965
load_normalize_table(layouter, "normalize_3", &self.normalize_3, 3u64)?;
@@ -969,7 +973,8 @@ impl<F: Field> KeccakCircuitConfig<F> {
969973
load_pack_table(layouter, &self.pack_table)
970974
}
971975

972-
fn annotate_circuit(&self, region: &mut Region<F>) {
976+
/// Annotate the circuit
977+
pub fn annotate_circuit(&self, region: &mut Region<F>) {
973978
//region.name_column(|| "KECCAK_q_enable", self.q_enable);
974979
region.name_column(|| "KECCAK_q_first", self.q_first);
975980
region.name_column(|| "KECCAK_q_round", self.q_round);

zkevm-circuits/src/keccak_circuit/cell_manager.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ impl<F: FieldExt> Expr<F> for &Cell<F> {
8989

9090
/// CellColumn
9191
#[derive(Clone, Debug)]
92-
pub(crate) struct CellColumn<F> {
93-
pub(crate) advice: Column<Advice>,
92+
pub struct CellColumn<F> {
93+
pub advice: Column<Advice>,
9494
pub(crate) expr: Expression<F>,
9595
}
9696

9797
/// CellManager
9898
#[derive(Clone, Debug)]
99-
pub(crate) struct CellManager<F> {
99+
pub struct CellManager<F> {
100100
height: usize,
101101
columns: Vec<CellColumn<F>>,
102102
rows: Vec<usize>,
@@ -153,7 +153,8 @@ impl<F: FieldExt> CellManager<F> {
153153
self.rows.iter().cloned().max().unwrap()
154154
}
155155

156-
pub(crate) fn columns(&self) -> &[CellColumn<F>] {
156+
/// expose the columns used for keccak cell
157+
pub fn columns(&self) -> &[CellColumn<F>] {
157158
&self.columns
158159
}
159160

zkevm-circuits/src/keccak_circuit/keccak_packed_multi.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,12 @@ pub struct KeccakRow<F: Field> {
6767
pub(crate) q_padding: bool,
6868
pub(crate) q_padding_last: bool,
6969
pub(crate) round_cst: F,
70-
pub(crate) is_final: bool,
71-
pub(crate) cell_values: Vec<F>,
72-
pub(crate) length: usize,
70+
/// if the row is the last row of the current keccak hash
71+
pub is_final: bool,
72+
/// the value of the cells that are to be assigned
73+
pub cell_values: Vec<F>,
74+
/// the length of the hash input
75+
pub length: usize,
7376
pub(crate) data_rlc: Value<F>,
7477
pub(crate) hash_rlc: Value<F>,
7578
}

0 commit comments

Comments
 (0)