Skip to content

Commit

Permalink
split-files: move more code
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurélien Nicolas committed Apr 8, 2023
1 parent 80d1d6f commit ece3d17
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 163 deletions.
14 changes: 7 additions & 7 deletions hashes/zkevm-keccak/src/keccak_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@ pub mod keccak_packed_multi;
mod keccak_table;
mod param;
mod table;
pub mod util;

#[cfg(test)]
mod test;
pub mod util;

use keccak_table::KeccakTable;
use std::marker::PhantomData;

use self::{cell_manager::*, keccak_packed_multi::*, param::*, table::*};
use param::{
CHI_BASE_LOOKUP_TABLE, NUM_BYTES_PER_WORD, NUM_ROUNDS, NUM_WORDS_TO_ABSORB,
NUM_WORDS_TO_SQUEEZE, RHO_MATRIX,
};
use util::{
constraint_builder::BaseConstraintBuilder,
eth_types::Field,
expression::{and, not, select, Expr},
get_absorb_positions, get_num_bits_per_lookup, rotate, scatter, target_part_sizes,
CHI_BASE_LOOKUP_TABLE, NUM_BYTES_PER_WORD, NUM_ROUNDS, NUM_WORDS_TO_ABSORB,
NUM_WORDS_TO_SQUEEZE, RHO_MATRIX,
};

use crate::halo2_proofs::{
Expand All @@ -30,9 +33,6 @@ use crate::halo2_proofs::{
use halo2_base::halo2_proofs::{circuit::AssignedCell, plonk::Assigned};
use itertools::Itertools;
use log::info;
use std::marker::PhantomData;

use self::{cell_manager::*, keccak_packed_multi::*, param::*, table::*};

#[cfg(feature = "halo2-axiom")]
type KeccakAssignedValue<'v, F> = AssignedCell<&'v Assigned<F>, F>;
Expand Down
18 changes: 10 additions & 8 deletions hashes/zkevm-keccak/src/keccak_circuit/keccak_packed_multi.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use super::keccak_table::KeccakTable;
use super::{assign_advice_custom, KeccakAssignedValue};
use super::{cell_manager::*, param::*};

use super::param::{
CHI_BASE_LOOKUP_TABLE, NUM_BYTES_PER_WORD, NUM_ROUNDS, NUM_WORDS_TO_ABSORB,
NUM_WORDS_TO_SQUEEZE, RATE, RATE_IN_BITS, RHO_MATRIX, ROUND_CST,
};
use super::util::{
constraint_builder::BaseConstraintBuilder, eth_types::Field, expression::Expr, field_xor,
get_absorb_positions, get_num_bits_per_lookup, into_bits, pack, pack_u64, pack_with_base,
rotate, target_part_sizes, to_bytes, unpack, CHI_BASE_LOOKUP_TABLE, NUM_BYTES_PER_WORD,
NUM_ROUNDS, NUM_WORDS_TO_ABSORB, NUM_WORDS_TO_SQUEEZE, RATE, RATE_IN_BITS, RHO_MATRIX,
ROUND_CST,
rotate, target_part_sizes, to_bytes, unpack,
};
use super::{assign_advice_custom, KeccakAssignedValue};
use super::{cell_manager::*, param::*};

use crate::halo2_proofs::{
arithmetic::FieldExt,
Expand Down Expand Up @@ -149,7 +150,7 @@ impl<F: FieldExt> KeccakRegion<F> {

/// Recombines parts back together
pub(crate) mod decode {
use super::super::util::BIT_COUNT;
use super::super::param::BIT_COUNT;
use super::{Expr, FieldExt, Part, PartValue};
use crate::halo2_proofs::plonk::Expression;

Expand Down Expand Up @@ -240,8 +241,9 @@ pub(crate) mod split {
// Split into parts, but storing the parts in a specific way to have the same
// table layout in `output_cells` regardless of rotation.
pub(crate) mod split_uniform {
use super::super::param::BIT_SIZE;
use super::super::util::{
eth_types::Field, pack, pack_part, rotate, rotate_rev, unpack, WordParts, BIT_SIZE,
eth_types::Field, pack, pack_part, rotate, rotate_rev, unpack, WordParts,
};
use super::{
decode, target_part_sizes, BaseConstraintBuilder, Cell, CellManager, Expr, FieldExt,
Expand Down
62 changes: 62 additions & 0 deletions hashes/zkevm-keccak/src/keccak_circuit/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,65 @@ pub(crate) const ABSORB_LOOKUP_RANGE: usize = 3;
pub(crate) const THETA_C_LOOKUP_RANGE: usize = 6;
pub(crate) const RHO_PI_LOOKUP_RANGE: usize = 4;
pub(crate) const CHI_BASE_LOOKUP_RANGE: usize = 5;

pub(crate) const NUM_BITS_PER_BYTE: usize = 8;
pub(crate) const NUM_BYTES_PER_WORD: usize = 8;
pub(crate) const NUM_BITS_PER_WORD: usize = NUM_BYTES_PER_WORD * NUM_BITS_PER_BYTE;
pub(crate) const KECCAK_WIDTH: usize = 5 * 5;
pub(crate) const KECCAK_WIDTH_IN_BITS: usize = KECCAK_WIDTH * NUM_BITS_PER_WORD;
pub(crate) const NUM_ROUNDS: usize = 24;
pub(crate) const NUM_WORDS_TO_ABSORB: usize = 17;
pub(crate) const NUM_BYTES_TO_ABSORB: usize = NUM_WORDS_TO_ABSORB * NUM_BYTES_PER_WORD;
pub(crate) const NUM_WORDS_TO_SQUEEZE: usize = 4;
pub(crate) const NUM_BYTES_TO_SQUEEZE: usize = NUM_WORDS_TO_SQUEEZE * NUM_BYTES_PER_WORD;
pub(crate) const ABSORB_WIDTH_PER_ROW: usize = NUM_BITS_PER_WORD;
pub(crate) const ABSORB_WIDTH_PER_ROW_BYTES: usize = ABSORB_WIDTH_PER_ROW / NUM_BITS_PER_BYTE;
pub(crate) const RATE: usize = NUM_WORDS_TO_ABSORB * NUM_BYTES_PER_WORD;
pub(crate) const RATE_IN_BITS: usize = RATE * NUM_BITS_PER_BYTE;
// pub(crate) const THETA_C_WIDTH: usize = 5 * NUM_BITS_PER_WORD;
pub(crate) const RHO_MATRIX: [[usize; 5]; 5] = [
[0, 36, 3, 41, 18],
[1, 44, 10, 45, 2],
[62, 6, 43, 15, 61],
[28, 55, 25, 21, 56],
[27, 20, 39, 8, 14],
];
pub(crate) const ROUND_CST: [u64; NUM_ROUNDS + 1] = [
0x0000000000000001,
0x0000000000008082,
0x800000000000808a,
0x8000000080008000,
0x000000000000808b,
0x0000000080000001,
0x8000000080008081,
0x8000000000008009,
0x000000000000008a,
0x0000000000000088,
0x0000000080008009,
0x000000008000000a,
0x000000008000808b,
0x800000000000008b,
0x8000000000008089,
0x8000000000008003,
0x8000000000008002,
0x8000000000000080,
0x000000000000800a,
0x800000008000000a,
0x8000000080008081,
0x8000000000008080,
0x0000000080000001,
0x8000000080008008,
0x0000000000000000, // absorb round
];
// Bit positions that have a non-zero value in `IOTA_ROUND_CST`.
// pub(crate) const ROUND_CST_BIT_POS: [usize; 7] = [0, 1, 3, 7, 15, 31, 63];

// The number of bits used in the sparse word representation per bit
pub(crate) const BIT_COUNT: usize = 3;
// The base of the bit in the sparse word representation
pub(crate) const BIT_SIZE: usize = 2usize.pow(BIT_COUNT as u32);

// `a ^ ((~b) & c)` is calculated by doing `lookup[3 - 2*a + b - c]`
pub(crate) const CHI_BASE_LOOKUP_TABLE: [u8; 5] = [0, 1, 1, 0, 0];
// `a ^ ((~b) & c) ^ d` is calculated by doing `lookup[5 - 2*a - b + c - 2*d]`
// pub(crate) const CHI_EXT_LOOKUP_TABLE: [u8; 7] = [0, 0, 1, 1, 0, 0, 1];
Loading

0 comments on commit ece3d17

Please sign in to comment.