use std::hash::Hash;
use strum::Display;
use strum::EnumCount;
use strum::EnumIter;
use crate::table::degree_lowering_table::DegreeLoweringBaseTableColumn;
use crate::table::degree_lowering_table::DegreeLoweringExtTableColumn;
use crate::table::master_table::CASCADE_TABLE_START;
use crate::table::master_table::DEGREE_LOWERING_TABLE_START;
use crate::table::master_table::EXT_CASCADE_TABLE_START;
use crate::table::master_table::EXT_DEGREE_LOWERING_TABLE_START;
use crate::table::master_table::EXT_HASH_TABLE_START;
use crate::table::master_table::EXT_JUMP_STACK_TABLE_START;
use crate::table::master_table::EXT_LOOKUP_TABLE_START;
use crate::table::master_table::EXT_OP_STACK_TABLE_START;
use crate::table::master_table::EXT_PROCESSOR_TABLE_START;
use crate::table::master_table::EXT_PROGRAM_TABLE_START;
use crate::table::master_table::EXT_RAM_TABLE_START;
use crate::table::master_table::EXT_U32_TABLE_START;
use crate::table::master_table::HASH_TABLE_START;
use crate::table::master_table::JUMP_STACK_TABLE_START;
use crate::table::master_table::LOOKUP_TABLE_START;
use crate::table::master_table::OP_STACK_TABLE_START;
use crate::table::master_table::PROCESSOR_TABLE_START;
use crate::table::master_table::PROGRAM_TABLE_START;
use crate::table::master_table::RAM_TABLE_START;
use crate::table::master_table::U32_TABLE_START;
#[repr(usize)]
#[derive(Debug, Display, Copy, Clone, Eq, PartialEq, Hash, EnumCount, EnumIter)]
pub enum ProgramBaseTableColumn {
Address,
Instruction,
LookupMultiplicity,
IndexInChunk,
MaxMinusIndexInChunkInv,
IsHashInputPadding,
IsTablePadding,
}
#[repr(usize)]
#[derive(Debug, Display, Copy, Clone, Eq, PartialEq, Hash, EnumCount, EnumIter)]
pub enum ProgramExtTableColumn {
InstructionLookupServerLogDerivative,
PrepareChunkRunningEvaluation,
SendChunkRunningEvaluation,
}
#[repr(usize)]
#[derive(Debug, Display, Copy, Clone, Eq, PartialEq, Hash, EnumCount, EnumIter)]
pub enum ProcessorBaseTableColumn {
CLK,
IsPadding,
IP,
CI,
NIA,
IB0,
IB1,
IB2,
IB3,
IB4,
IB5,
IB6,
JSP,
JSO,
JSD,
ST0,
ST1,
ST2,
ST3,
ST4,
ST5,
ST6,
ST7,
ST8,
ST9,
ST10,
ST11,
ST12,
ST13,
ST14,
ST15,
OpStackPointer,
HV0,
HV1,
HV2,
HV3,
HV4,
HV5,
ClockJumpDifferenceLookupMultiplicity,
}
#[repr(usize)]
#[derive(Debug, Display, Copy, Clone, Eq, PartialEq, Hash, EnumCount, EnumIter)]
pub enum ProcessorExtTableColumn {
InputTableEvalArg,
OutputTableEvalArg,
InstructionLookupClientLogDerivative,
OpStackTablePermArg,
RamTablePermArg,
JumpStackTablePermArg,
HashInputEvalArg,
HashDigestEvalArg,
SpongeEvalArg,
U32LookupClientLogDerivative,
ClockJumpDifferenceLookupServerLogDerivative,
}
#[repr(usize)]
#[derive(Debug, Display, Copy, Clone, Eq, PartialEq, Hash, EnumCount, EnumIter)]
pub enum OpStackBaseTableColumn {
CLK,
IB1ShrinkStack,
StackPointer,
FirstUnderflowElement,
}
#[repr(usize)]
#[derive(Debug, Display, Copy, Clone, Eq, PartialEq, Hash, EnumCount, EnumIter)]
pub enum OpStackExtTableColumn {
RunningProductPermArg,
ClockJumpDifferenceLookupClientLogDerivative,
}
#[repr(usize)]
#[derive(Debug, Display, Copy, Clone, Eq, PartialEq, Hash, EnumCount, EnumIter)]
pub enum RamBaseTableColumn {
CLK,
InstructionType,
RamPointer,
RamValue,
InverseOfRampDifference,
BezoutCoefficientPolynomialCoefficient0,
BezoutCoefficientPolynomialCoefficient1,
}
#[repr(usize)]
#[derive(Debug, Display, Copy, Clone, Eq, PartialEq, Hash, EnumCount, EnumIter)]
pub enum RamExtTableColumn {
RunningProductOfRAMP,
FormalDerivative,
BezoutCoefficient0,
BezoutCoefficient1,
RunningProductPermArg,
ClockJumpDifferenceLookupClientLogDerivative,
}
#[repr(usize)]
#[derive(Debug, Display, Copy, Clone, Eq, PartialEq, Hash, EnumCount, EnumIter)]
pub enum JumpStackBaseTableColumn {
CLK,
CI,
JSP,
JSO,
JSD,
}
#[repr(usize)]
#[derive(Debug, Display, Copy, Clone, Eq, PartialEq, Hash, EnumCount, EnumIter)]
pub enum JumpStackExtTableColumn {
RunningProductPermArg,
ClockJumpDifferenceLookupClientLogDerivative,
}
#[repr(usize)]
#[derive(Debug, Display, Copy, Clone, Eq, PartialEq, Hash, EnumCount, EnumIter)]
pub enum HashBaseTableColumn {
Mode,
CI,
RoundNumber,
State0HighestLkIn,
State0MidHighLkIn,
State0MidLowLkIn,
State0LowestLkIn,
State1HighestLkIn,
State1MidHighLkIn,
State1MidLowLkIn,
State1LowestLkIn,
State2HighestLkIn,
State2MidHighLkIn,
State2MidLowLkIn,
State2LowestLkIn,
State3HighestLkIn,
State3MidHighLkIn,
State3MidLowLkIn,
State3LowestLkIn,
State0HighestLkOut,
State0MidHighLkOut,
State0MidLowLkOut,
State0LowestLkOut,
State1HighestLkOut,
State1MidHighLkOut,
State1MidLowLkOut,
State1LowestLkOut,
State2HighestLkOut,
State2MidHighLkOut,
State2MidLowLkOut,
State2LowestLkOut,
State3HighestLkOut,
State3MidHighLkOut,
State3MidLowLkOut,
State3LowestLkOut,
State4,
State5,
State6,
State7,
State8,
State9,
State10,
State11,
State12,
State13,
State14,
State15,
State0Inv,
State1Inv,
State2Inv,
State3Inv,
Constant0,
Constant1,
Constant2,
Constant3,
Constant4,
Constant5,
Constant6,
Constant7,
Constant8,
Constant9,
Constant10,
Constant11,
Constant12,
Constant13,
Constant14,
Constant15,
}
#[repr(usize)]
#[derive(Debug, Display, Copy, Clone, Eq, PartialEq, Hash, EnumCount, EnumIter)]
pub enum HashExtTableColumn {
ReceiveChunkRunningEvaluation,
HashInputRunningEvaluation,
HashDigestRunningEvaluation,
SpongeRunningEvaluation,
CascadeState0HighestClientLogDerivative,
CascadeState0MidHighClientLogDerivative,
CascadeState0MidLowClientLogDerivative,
CascadeState0LowestClientLogDerivative,
CascadeState1HighestClientLogDerivative,
CascadeState1MidHighClientLogDerivative,
CascadeState1MidLowClientLogDerivative,
CascadeState1LowestClientLogDerivative,
CascadeState2HighestClientLogDerivative,
CascadeState2MidHighClientLogDerivative,
CascadeState2MidLowClientLogDerivative,
CascadeState2LowestClientLogDerivative,
CascadeState3HighestClientLogDerivative,
CascadeState3MidHighClientLogDerivative,
CascadeState3MidLowClientLogDerivative,
CascadeState3LowestClientLogDerivative,
}
#[repr(usize)]
#[derive(Debug, Display, Copy, Clone, Eq, PartialEq, Hash, EnumCount, EnumIter)]
pub enum CascadeBaseTableColumn {
IsPadding,
LookInHi,
LookInLo,
LookOutHi,
LookOutLo,
LookupMultiplicity,
}
#[repr(usize)]
#[derive(Debug, Display, Copy, Clone, Eq, PartialEq, Hash, EnumCount, EnumIter)]
pub enum CascadeExtTableColumn {
HashTableServerLogDerivative,
LookupTableClientLogDerivative,
}
#[repr(usize)]
#[derive(Debug, Display, Copy, Clone, Eq, PartialEq, Hash, EnumCount, EnumIter)]
pub enum LookupBaseTableColumn {
IsPadding,
LookIn,
LookOut,
LookupMultiplicity,
}
#[repr(usize)]
#[derive(Debug, Display, Copy, Clone, Eq, PartialEq, Hash, EnumCount, EnumIter)]
pub enum LookupExtTableColumn {
CascadeTableServerLogDerivative,
PublicEvaluationArgument,
}
#[repr(usize)]
#[derive(Debug, Display, Copy, Clone, Eq, PartialEq, Hash, EnumCount, EnumIter)]
pub enum U32BaseTableColumn {
CopyFlag,
Bits,
BitsMinus33Inv,
CI,
LHS,
LhsInv,
RHS,
RhsInv,
Result,
LookupMultiplicity,
}
#[repr(usize)]
#[derive(Debug, Display, Copy, Clone, Eq, PartialEq, Hash, EnumCount, EnumIter)]
pub enum U32ExtTableColumn {
LookupServerLogDerivative,
}
pub trait MasterBaseTableColumn {
fn base_table_index(&self) -> usize;
fn master_base_table_index(&self) -> usize;
}
impl MasterBaseTableColumn for ProgramBaseTableColumn {
#[inline]
fn base_table_index(&self) -> usize {
(*self) as usize
}
#[inline]
fn master_base_table_index(&self) -> usize {
PROGRAM_TABLE_START + self.base_table_index()
}
}
impl MasterBaseTableColumn for ProcessorBaseTableColumn {
#[inline]
fn base_table_index(&self) -> usize {
(*self) as usize
}
#[inline]
fn master_base_table_index(&self) -> usize {
PROCESSOR_TABLE_START + self.base_table_index()
}
}
impl MasterBaseTableColumn for OpStackBaseTableColumn {
#[inline]
fn base_table_index(&self) -> usize {
(*self) as usize
}
#[inline]
fn master_base_table_index(&self) -> usize {
OP_STACK_TABLE_START + self.base_table_index()
}
}
impl MasterBaseTableColumn for RamBaseTableColumn {
#[inline]
fn base_table_index(&self) -> usize {
(*self) as usize
}
#[inline]
fn master_base_table_index(&self) -> usize {
RAM_TABLE_START + self.base_table_index()
}
}
impl MasterBaseTableColumn for JumpStackBaseTableColumn {
#[inline]
fn base_table_index(&self) -> usize {
(*self) as usize
}
#[inline]
fn master_base_table_index(&self) -> usize {
JUMP_STACK_TABLE_START + self.base_table_index()
}
}
impl MasterBaseTableColumn for HashBaseTableColumn {
#[inline]
fn base_table_index(&self) -> usize {
(*self) as usize
}
#[inline]
fn master_base_table_index(&self) -> usize {
HASH_TABLE_START + self.base_table_index()
}
}
impl MasterBaseTableColumn for CascadeBaseTableColumn {
#[inline]
fn base_table_index(&self) -> usize {
(*self) as usize
}
#[inline]
fn master_base_table_index(&self) -> usize {
CASCADE_TABLE_START + self.base_table_index()
}
}
impl MasterBaseTableColumn for LookupBaseTableColumn {
#[inline]
fn base_table_index(&self) -> usize {
(*self) as usize
}
#[inline]
fn master_base_table_index(&self) -> usize {
LOOKUP_TABLE_START + self.base_table_index()
}
}
impl MasterBaseTableColumn for U32BaseTableColumn {
#[inline]
fn base_table_index(&self) -> usize {
(*self) as usize
}
#[inline]
fn master_base_table_index(&self) -> usize {
U32_TABLE_START + self.base_table_index()
}
}
impl MasterBaseTableColumn for DegreeLoweringBaseTableColumn {
#[inline]
fn base_table_index(&self) -> usize {
(*self) as usize
}
#[inline]
fn master_base_table_index(&self) -> usize {
DEGREE_LOWERING_TABLE_START + self.base_table_index()
}
}
pub trait MasterExtTableColumn {
fn ext_table_index(&self) -> usize;
fn master_ext_table_index(&self) -> usize;
}
impl MasterExtTableColumn for ProgramExtTableColumn {
#[inline]
fn ext_table_index(&self) -> usize {
(*self) as usize
}
#[inline]
fn master_ext_table_index(&self) -> usize {
EXT_PROGRAM_TABLE_START + self.ext_table_index()
}
}
impl MasterExtTableColumn for ProcessorExtTableColumn {
#[inline]
fn ext_table_index(&self) -> usize {
(*self) as usize
}
#[inline]
fn master_ext_table_index(&self) -> usize {
EXT_PROCESSOR_TABLE_START + self.ext_table_index()
}
}
impl MasterExtTableColumn for OpStackExtTableColumn {
#[inline]
fn ext_table_index(&self) -> usize {
(*self) as usize
}
#[inline]
fn master_ext_table_index(&self) -> usize {
EXT_OP_STACK_TABLE_START + self.ext_table_index()
}
}
impl MasterExtTableColumn for RamExtTableColumn {
#[inline]
fn ext_table_index(&self) -> usize {
(*self) as usize
}
#[inline]
fn master_ext_table_index(&self) -> usize {
EXT_RAM_TABLE_START + self.ext_table_index()
}
}
impl MasterExtTableColumn for JumpStackExtTableColumn {
#[inline]
fn ext_table_index(&self) -> usize {
(*self) as usize
}
#[inline]
fn master_ext_table_index(&self) -> usize {
EXT_JUMP_STACK_TABLE_START + self.ext_table_index()
}
}
impl MasterExtTableColumn for HashExtTableColumn {
#[inline]
fn ext_table_index(&self) -> usize {
(*self) as usize
}
#[inline]
fn master_ext_table_index(&self) -> usize {
EXT_HASH_TABLE_START + self.ext_table_index()
}
}
impl MasterExtTableColumn for CascadeExtTableColumn {
#[inline]
fn ext_table_index(&self) -> usize {
(*self) as usize
}
#[inline]
fn master_ext_table_index(&self) -> usize {
EXT_CASCADE_TABLE_START + self.ext_table_index()
}
}
impl MasterExtTableColumn for LookupExtTableColumn {
#[inline]
fn ext_table_index(&self) -> usize {
(*self) as usize
}
#[inline]
fn master_ext_table_index(&self) -> usize {
EXT_LOOKUP_TABLE_START + self.ext_table_index()
}
}
impl MasterExtTableColumn for U32ExtTableColumn {
#[inline]
fn ext_table_index(&self) -> usize {
(*self) as usize
}
#[inline]
fn master_ext_table_index(&self) -> usize {
EXT_U32_TABLE_START + self.ext_table_index()
}
}
impl MasterExtTableColumn for DegreeLoweringExtTableColumn {
#[inline]
fn ext_table_index(&self) -> usize {
(*self) as usize
}
#[inline]
fn master_ext_table_index(&self) -> usize {
EXT_DEGREE_LOWERING_TABLE_START + self.ext_table_index()
}
}
#[cfg(test)]
mod tests {
use strum::IntoEnumIterator;
use crate::table::cascade_table;
use crate::table::hash_table;
use crate::table::jump_stack_table;
use crate::table::lookup_table;
use crate::table::op_stack_table;
use crate::table::processor_table;
use crate::table::program_table;
use crate::table::ram_table;
use crate::table::u32_table;
use super::*;
#[test]
fn column_max_bound_matches_table_width() {
assert_eq!(
program_table::BASE_WIDTH,
ProgramBaseTableColumn::iter()
.last()
.unwrap()
.base_table_index()
+ 1,
"ProgramTable's BASE_WIDTH is 1 + its max column index",
);
assert_eq!(
processor_table::BASE_WIDTH,
ProcessorBaseTableColumn::iter()
.last()
.unwrap()
.base_table_index()
+ 1,
"ProcessorTable's BASE_WIDTH is 1 + its max column index",
);
assert_eq!(
op_stack_table::BASE_WIDTH,
OpStackBaseTableColumn::iter()
.last()
.unwrap()
.base_table_index()
+ 1,
"OpStackTable's BASE_WIDTH is 1 + its max column index",
);
assert_eq!(
ram_table::BASE_WIDTH,
RamBaseTableColumn::iter()
.last()
.unwrap()
.base_table_index()
+ 1,
"RamTable's BASE_WIDTH is 1 + its max column index",
);
assert_eq!(
jump_stack_table::BASE_WIDTH,
JumpStackBaseTableColumn::iter()
.last()
.unwrap()
.base_table_index()
+ 1,
"JumpStackTable's BASE_WIDTH is 1 + its max column index",
);
assert_eq!(
hash_table::BASE_WIDTH,
HashBaseTableColumn::iter()
.last()
.unwrap()
.base_table_index()
+ 1,
"HashTable's BASE_WIDTH is 1 + its max column index",
);
assert_eq!(
cascade_table::BASE_WIDTH,
CascadeBaseTableColumn::iter()
.last()
.unwrap()
.base_table_index()
+ 1,
"CascadeTable's BASE_WIDTH is 1 + its max column index",
);
assert_eq!(
lookup_table::BASE_WIDTH,
LookupBaseTableColumn::iter()
.last()
.unwrap()
.base_table_index()
+ 1,
"LookupTable's BASE_WIDTH is 1 + its max column index",
);
assert_eq!(
u32_table::BASE_WIDTH,
U32BaseTableColumn::iter()
.last()
.unwrap()
.base_table_index()
+ 1,
"U32Table's BASE_WIDTH is 1 + its max column index",
);
assert_eq!(
program_table::EXT_WIDTH,
ProgramExtTableColumn::iter()
.last()
.unwrap()
.ext_table_index()
+ 1,
"ProgramTable's EXT_WIDTH is 1 + its max column index",
);
assert_eq!(
processor_table::EXT_WIDTH,
ProcessorExtTableColumn::iter()
.last()
.unwrap()
.ext_table_index()
+ 1,
"ProcessorTable's EXT_WIDTH is 1 + its max column index",
);
assert_eq!(
op_stack_table::EXT_WIDTH,
OpStackExtTableColumn::iter()
.last()
.unwrap()
.ext_table_index()
+ 1,
"OpStack:Table's EXT_WIDTH is 1 + its max column index",
);
assert_eq!(
ram_table::EXT_WIDTH,
RamExtTableColumn::iter().last().unwrap().ext_table_index() + 1,
"RamTable's EXT_WIDTH is 1 + its max column index",
);
assert_eq!(
jump_stack_table::EXT_WIDTH,
JumpStackExtTableColumn::iter()
.last()
.unwrap()
.ext_table_index()
+ 1,
"JumpStack:Table's EXT_WIDTH is 1 + its max column index",
);
assert_eq!(
hash_table::EXT_WIDTH,
HashExtTableColumn::iter().last().unwrap().ext_table_index() + 1,
"HashTable's EXT_WIDTH is 1 + its max column index",
);
assert_eq!(
cascade_table::EXT_WIDTH,
CascadeExtTableColumn::iter()
.last()
.unwrap()
.ext_table_index()
+ 1,
"CascadeTable's EXT_WIDTH is 1 + its max column index",
);
assert_eq!(
lookup_table::EXT_WIDTH,
LookupExtTableColumn::iter()
.last()
.unwrap()
.ext_table_index()
+ 1,
"LookupTable's EXT_WIDTH is 1 + its max column index",
);
assert_eq!(
u32_table::EXT_WIDTH,
U32ExtTableColumn::iter().last().unwrap().ext_table_index() + 1,
"U32Table's EXT_WIDTH is 1 + its max column index",
);
}
#[test]
fn master_base_table_is_contiguous() {
let mut expected_column_index = 0;
for column in ProgramBaseTableColumn::iter() {
assert_eq!(expected_column_index, column.master_base_table_index());
expected_column_index += 1;
}
for column in ProcessorBaseTableColumn::iter() {
assert_eq!(expected_column_index, column.master_base_table_index());
expected_column_index += 1;
}
for column in OpStackBaseTableColumn::iter() {
assert_eq!(expected_column_index, column.master_base_table_index());
expected_column_index += 1;
}
for column in RamBaseTableColumn::iter() {
assert_eq!(expected_column_index, column.master_base_table_index());
expected_column_index += 1;
}
for column in JumpStackBaseTableColumn::iter() {
assert_eq!(expected_column_index, column.master_base_table_index());
expected_column_index += 1;
}
for column in HashBaseTableColumn::iter() {
assert_eq!(expected_column_index, column.master_base_table_index());
expected_column_index += 1;
}
for column in CascadeBaseTableColumn::iter() {
assert_eq!(expected_column_index, column.master_base_table_index());
expected_column_index += 1;
}
for column in LookupBaseTableColumn::iter() {
assert_eq!(expected_column_index, column.master_base_table_index());
expected_column_index += 1;
}
for column in U32BaseTableColumn::iter() {
assert_eq!(expected_column_index, column.master_base_table_index());
expected_column_index += 1;
}
for column in DegreeLoweringBaseTableColumn::iter() {
assert_eq!(expected_column_index, column.master_base_table_index());
expected_column_index += 1;
}
}
#[test]
fn master_ext_table_is_contiguous() {
let mut expected_column_index = 0;
for column in ProgramExtTableColumn::iter() {
assert_eq!(expected_column_index, column.master_ext_table_index());
expected_column_index += 1;
}
for column in ProcessorExtTableColumn::iter() {
assert_eq!(expected_column_index, column.master_ext_table_index());
expected_column_index += 1;
}
for column in OpStackExtTableColumn::iter() {
assert_eq!(expected_column_index, column.master_ext_table_index());
expected_column_index += 1;
}
for column in RamExtTableColumn::iter() {
assert_eq!(expected_column_index, column.master_ext_table_index());
expected_column_index += 1;
}
for column in JumpStackExtTableColumn::iter() {
assert_eq!(expected_column_index, column.master_ext_table_index());
expected_column_index += 1;
}
for column in HashExtTableColumn::iter() {
assert_eq!(expected_column_index, column.master_ext_table_index());
expected_column_index += 1;
}
for column in CascadeExtTableColumn::iter() {
assert_eq!(expected_column_index, column.master_ext_table_index());
expected_column_index += 1;
}
for column in LookupExtTableColumn::iter() {
assert_eq!(expected_column_index, column.master_ext_table_index());
expected_column_index += 1;
}
for column in U32ExtTableColumn::iter() {
assert_eq!(expected_column_index, column.master_ext_table_index());
expected_column_index += 1;
}
for column in DegreeLoweringExtTableColumn::iter() {
assert_eq!(expected_column_index, column.master_ext_table_index());
expected_column_index += 1;
}
}
}