2022-09-22 18:09:23 -07:00
|
|
|
use std::iter;
|
|
|
|
|
|
2022-06-27 07:18:21 -07:00
|
|
|
use plonky2::field::extension::Extendable;
|
2022-06-27 12:24:09 -07:00
|
|
|
use plonky2::field::types::Field;
|
2022-05-06 17:22:30 +02:00
|
|
|
use plonky2::hash::hash_types::RichField;
|
|
|
|
|
|
Cross-table lookup for arithmetic stark (#905)
* First draft of linking arithmetic Stark into the CTL mechanism.
* Handle {ADD,SUB,MUL}FP254 operations explicitly in `modular.rs`.
* Adjust argument order; add tests.
* Add CTLs for ADD, MUL, SUB, LT and GT.
* Add CTLs for {ADD,MUL,SUB}MOD, DIV and MOD.
* Add CTLs for {ADD,MUL,SUB}FP254 operations.
* Refactor the CPU/arithmetic CTL mapping; add some documentation.
* Minor comment fixes.
* Combine addcy CTLs at the expense of repeated constraint evaluation.
* Combine addcy CTLs at the expense of repeated constraint evaluation.
* Merge `*FP254` CTL into main CTL; rename some registers.
* Connect extra argument from CPU in binary ops to facilitate combining with ternary ops.
* Merge modular ops CTL into main CTL.
* Refactor DIV and MOD code into its own module.
* Merge DIV and MOD into arithmetic CTL.
* Clippy.
* Fixes related to merge.
* Simplify register naming.
* Generate u16 BN254 modulus limbs at compile time.
* Clippy.
* Add degree bits ranges for Arithmetic table.
2023-05-11 03:29:06 +10:00
|
|
|
use crate::arithmetic::arithmetic_stark;
|
|
|
|
|
use crate::arithmetic::arithmetic_stark::ArithmeticStark;
|
2023-09-12 14:45:37 -04:00
|
|
|
use crate::byte_packing::byte_packing_stark::{self, BytePackingStark};
|
2022-05-13 10:48:56 +02:00
|
|
|
use crate::config::StarkConfig;
|
2022-06-27 10:40:16 -07:00
|
|
|
use crate::cpu::cpu_stark;
|
2022-05-18 09:22:58 +02:00
|
|
|
use crate::cpu::cpu_stark::CpuStark;
|
2022-09-22 18:09:23 -07:00
|
|
|
use crate::cpu::membus::NUM_GP_CHANNELS;
|
2023-04-14 21:55:44 +08:00
|
|
|
use crate::cross_table_lookup::{CrossTableLookup, TableWithColumns};
|
2022-06-27 10:40:16 -07:00
|
|
|
use crate::keccak::keccak_stark;
|
2022-05-18 09:22:58 +02:00
|
|
|
use crate::keccak::keccak_stark::KeccakStark;
|
2022-12-03 11:22:56 -08:00
|
|
|
use crate::keccak_sponge::columns::KECCAK_RATE_BYTES;
|
2022-12-03 11:21:31 -08:00
|
|
|
use crate::keccak_sponge::keccak_sponge_stark;
|
2022-12-15 13:56:48 -08:00
|
|
|
use crate::keccak_sponge::keccak_sponge_stark::KeccakSpongeStark;
|
2022-06-27 10:40:16 -07:00
|
|
|
use crate::logic;
|
2022-06-17 11:57:14 -07:00
|
|
|
use crate::logic::LogicStark;
|
2022-09-22 18:09:23 -07:00
|
|
|
use crate::memory::memory_stark;
|
2022-06-23 13:59:57 -07:00
|
|
|
use crate::memory::memory_stark::MemoryStark;
|
2022-05-06 17:22:30 +02:00
|
|
|
use crate::stark::Stark;
|
|
|
|
|
|
2023-10-30 14:28:24 -04:00
|
|
|
/// Structure containing all STARKs and the cross-table lookups.
|
2022-05-12 20:38:11 +02:00
|
|
|
#[derive(Clone)]
|
2022-05-06 17:35:25 +02:00
|
|
|
pub struct AllStark<F: RichField + Extendable<D>, const D: usize> {
|
2023-11-13 09:26:56 -05:00
|
|
|
pub(crate) arithmetic_stark: ArithmeticStark<F, D>,
|
|
|
|
|
pub(crate) byte_packing_stark: BytePackingStark<F, D>,
|
|
|
|
|
pub(crate) cpu_stark: CpuStark<F, D>,
|
|
|
|
|
pub(crate) keccak_stark: KeccakStark<F, D>,
|
|
|
|
|
pub(crate) keccak_sponge_stark: KeccakSpongeStark<F, D>,
|
|
|
|
|
pub(crate) logic_stark: LogicStark<F, D>,
|
|
|
|
|
pub(crate) memory_stark: MemoryStark<F, D>,
|
|
|
|
|
pub(crate) cross_table_lookups: Vec<CrossTableLookup<F>>,
|
2022-05-06 17:22:30 +02:00
|
|
|
}
|
|
|
|
|
|
2022-07-04 18:10:03 -07:00
|
|
|
impl<F: RichField + Extendable<D>, const D: usize> Default for AllStark<F, D> {
|
2023-10-30 14:28:24 -04:00
|
|
|
/// Returns an `AllStark` containing all the STARKs initialized with default values.
|
2022-07-04 18:10:03 -07:00
|
|
|
fn default() -> Self {
|
|
|
|
|
Self {
|
Cross-table lookup for arithmetic stark (#905)
* First draft of linking arithmetic Stark into the CTL mechanism.
* Handle {ADD,SUB,MUL}FP254 operations explicitly in `modular.rs`.
* Adjust argument order; add tests.
* Add CTLs for ADD, MUL, SUB, LT and GT.
* Add CTLs for {ADD,MUL,SUB}MOD, DIV and MOD.
* Add CTLs for {ADD,MUL,SUB}FP254 operations.
* Refactor the CPU/arithmetic CTL mapping; add some documentation.
* Minor comment fixes.
* Combine addcy CTLs at the expense of repeated constraint evaluation.
* Combine addcy CTLs at the expense of repeated constraint evaluation.
* Merge `*FP254` CTL into main CTL; rename some registers.
* Connect extra argument from CPU in binary ops to facilitate combining with ternary ops.
* Merge modular ops CTL into main CTL.
* Refactor DIV and MOD code into its own module.
* Merge DIV and MOD into arithmetic CTL.
* Clippy.
* Fixes related to merge.
* Simplify register naming.
* Generate u16 BN254 modulus limbs at compile time.
* Clippy.
* Add degree bits ranges for Arithmetic table.
2023-05-11 03:29:06 +10:00
|
|
|
arithmetic_stark: ArithmeticStark::default(),
|
2023-09-12 14:45:37 -04:00
|
|
|
byte_packing_stark: BytePackingStark::default(),
|
2022-07-04 18:10:03 -07:00
|
|
|
cpu_stark: CpuStark::default(),
|
|
|
|
|
keccak_stark: KeccakStark::default(),
|
2022-12-03 11:21:31 -08:00
|
|
|
keccak_sponge_stark: KeccakSpongeStark::default(),
|
2022-07-04 18:10:03 -07:00
|
|
|
logic_stark: LogicStark::default(),
|
|
|
|
|
memory_stark: MemoryStark::default(),
|
|
|
|
|
cross_table_lookups: all_cross_table_lookups(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-13 10:48:56 +02:00
|
|
|
impl<F: RichField + Extendable<D>, const D: usize> AllStark<F, D> {
|
2023-02-13 15:58:26 +01:00
|
|
|
pub(crate) fn num_lookups_helper_columns(&self, config: &StarkConfig) -> [usize; NUM_TABLES] {
|
2022-08-26 10:12:45 +02:00
|
|
|
[
|
2023-02-13 15:58:26 +01:00
|
|
|
self.arithmetic_stark.num_lookup_helper_columns(config),
|
|
|
|
|
self.byte_packing_stark.num_lookup_helper_columns(config),
|
|
|
|
|
self.cpu_stark.num_lookup_helper_columns(config),
|
|
|
|
|
self.keccak_stark.num_lookup_helper_columns(config),
|
|
|
|
|
self.keccak_sponge_stark.num_lookup_helper_columns(config),
|
|
|
|
|
self.logic_stark.num_lookup_helper_columns(config),
|
|
|
|
|
self.memory_stark.num_lookup_helper_columns(config),
|
2022-08-26 10:12:45 +02:00
|
|
|
]
|
2022-05-13 10:48:56 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-30 14:28:24 -04:00
|
|
|
/// Associates STARK tables with a unique index.
|
2022-08-25 22:04:28 +02:00
|
|
|
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
2022-05-06 17:22:30 +02:00
|
|
|
pub enum Table {
|
Cross-table lookup for arithmetic stark (#905)
* First draft of linking arithmetic Stark into the CTL mechanism.
* Handle {ADD,SUB,MUL}FP254 operations explicitly in `modular.rs`.
* Adjust argument order; add tests.
* Add CTLs for ADD, MUL, SUB, LT and GT.
* Add CTLs for {ADD,MUL,SUB}MOD, DIV and MOD.
* Add CTLs for {ADD,MUL,SUB}FP254 operations.
* Refactor the CPU/arithmetic CTL mapping; add some documentation.
* Minor comment fixes.
* Combine addcy CTLs at the expense of repeated constraint evaluation.
* Combine addcy CTLs at the expense of repeated constraint evaluation.
* Merge `*FP254` CTL into main CTL; rename some registers.
* Connect extra argument from CPU in binary ops to facilitate combining with ternary ops.
* Merge modular ops CTL into main CTL.
* Refactor DIV and MOD code into its own module.
* Merge DIV and MOD into arithmetic CTL.
* Clippy.
* Fixes related to merge.
* Simplify register naming.
* Generate u16 BN254 modulus limbs at compile time.
* Clippy.
* Add degree bits ranges for Arithmetic table.
2023-05-11 03:29:06 +10:00
|
|
|
Arithmetic = 0,
|
2023-09-12 14:45:37 -04:00
|
|
|
BytePacking = 1,
|
|
|
|
|
Cpu = 2,
|
|
|
|
|
Keccak = 3,
|
|
|
|
|
KeccakSponge = 4,
|
|
|
|
|
Logic = 5,
|
|
|
|
|
Memory = 6,
|
2022-05-06 17:22:30 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-30 14:28:24 -04:00
|
|
|
/// Number of STARK tables.
|
2022-08-26 10:12:45 +02:00
|
|
|
pub(crate) const NUM_TABLES: usize = Table::Memory as usize + 1;
|
2022-05-19 09:41:15 +02:00
|
|
|
|
2022-12-09 12:51:42 -08:00
|
|
|
impl Table {
|
2023-10-30 14:28:24 -04:00
|
|
|
/// Returns all STARK table indices.
|
2022-12-09 12:51:42 -08:00
|
|
|
pub(crate) fn all() -> [Self; NUM_TABLES] {
|
|
|
|
|
[
|
Cross-table lookup for arithmetic stark (#905)
* First draft of linking arithmetic Stark into the CTL mechanism.
* Handle {ADD,SUB,MUL}FP254 operations explicitly in `modular.rs`.
* Adjust argument order; add tests.
* Add CTLs for ADD, MUL, SUB, LT and GT.
* Add CTLs for {ADD,MUL,SUB}MOD, DIV and MOD.
* Add CTLs for {ADD,MUL,SUB}FP254 operations.
* Refactor the CPU/arithmetic CTL mapping; add some documentation.
* Minor comment fixes.
* Combine addcy CTLs at the expense of repeated constraint evaluation.
* Combine addcy CTLs at the expense of repeated constraint evaluation.
* Merge `*FP254` CTL into main CTL; rename some registers.
* Connect extra argument from CPU in binary ops to facilitate combining with ternary ops.
* Merge modular ops CTL into main CTL.
* Refactor DIV and MOD code into its own module.
* Merge DIV and MOD into arithmetic CTL.
* Clippy.
* Fixes related to merge.
* Simplify register naming.
* Generate u16 BN254 modulus limbs at compile time.
* Clippy.
* Add degree bits ranges for Arithmetic table.
2023-05-11 03:29:06 +10:00
|
|
|
Self::Arithmetic,
|
2023-09-12 14:45:37 -04:00
|
|
|
Self::BytePacking,
|
2022-12-09 12:51:42 -08:00
|
|
|
Self::Cpu,
|
|
|
|
|
Self::Keccak,
|
|
|
|
|
Self::KeccakSponge,
|
|
|
|
|
Self::Logic,
|
|
|
|
|
Self::Memory,
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-30 14:28:24 -04:00
|
|
|
/// Returns all the `CrossTableLookups` used for proving the EVM.
|
2022-06-27 10:40:16 -07:00
|
|
|
pub(crate) fn all_cross_table_lookups<F: Field>() -> Vec<CrossTableLookup<F>> {
|
2023-04-14 21:55:44 +08:00
|
|
|
vec![
|
Cross-table lookup for arithmetic stark (#905)
* First draft of linking arithmetic Stark into the CTL mechanism.
* Handle {ADD,SUB,MUL}FP254 operations explicitly in `modular.rs`.
* Adjust argument order; add tests.
* Add CTLs for ADD, MUL, SUB, LT and GT.
* Add CTLs for {ADD,MUL,SUB}MOD, DIV and MOD.
* Add CTLs for {ADD,MUL,SUB}FP254 operations.
* Refactor the CPU/arithmetic CTL mapping; add some documentation.
* Minor comment fixes.
* Combine addcy CTLs at the expense of repeated constraint evaluation.
* Combine addcy CTLs at the expense of repeated constraint evaluation.
* Merge `*FP254` CTL into main CTL; rename some registers.
* Connect extra argument from CPU in binary ops to facilitate combining with ternary ops.
* Merge modular ops CTL into main CTL.
* Refactor DIV and MOD code into its own module.
* Merge DIV and MOD into arithmetic CTL.
* Clippy.
* Fixes related to merge.
* Simplify register naming.
* Generate u16 BN254 modulus limbs at compile time.
* Clippy.
* Add degree bits ranges for Arithmetic table.
2023-05-11 03:29:06 +10:00
|
|
|
ctl_arithmetic(),
|
2023-09-12 14:45:37 -04:00
|
|
|
ctl_byte_packing(),
|
Cross-table lookup for arithmetic stark (#905)
* First draft of linking arithmetic Stark into the CTL mechanism.
* Handle {ADD,SUB,MUL}FP254 operations explicitly in `modular.rs`.
* Adjust argument order; add tests.
* Add CTLs for ADD, MUL, SUB, LT and GT.
* Add CTLs for {ADD,MUL,SUB}MOD, DIV and MOD.
* Add CTLs for {ADD,MUL,SUB}FP254 operations.
* Refactor the CPU/arithmetic CTL mapping; add some documentation.
* Minor comment fixes.
* Combine addcy CTLs at the expense of repeated constraint evaluation.
* Combine addcy CTLs at the expense of repeated constraint evaluation.
* Merge `*FP254` CTL into main CTL; rename some registers.
* Connect extra argument from CPU in binary ops to facilitate combining with ternary ops.
* Merge modular ops CTL into main CTL.
* Refactor DIV and MOD code into its own module.
* Merge DIV and MOD into arithmetic CTL.
* Clippy.
* Fixes related to merge.
* Simplify register naming.
* Generate u16 BN254 modulus limbs at compile time.
* Clippy.
* Add degree bits ranges for Arithmetic table.
2023-05-11 03:29:06 +10:00
|
|
|
ctl_keccak_sponge(),
|
2023-10-06 15:49:57 -04:00
|
|
|
ctl_keccak_inputs(),
|
|
|
|
|
ctl_keccak_outputs(),
|
Cross-table lookup for arithmetic stark (#905)
* First draft of linking arithmetic Stark into the CTL mechanism.
* Handle {ADD,SUB,MUL}FP254 operations explicitly in `modular.rs`.
* Adjust argument order; add tests.
* Add CTLs for ADD, MUL, SUB, LT and GT.
* Add CTLs for {ADD,MUL,SUB}MOD, DIV and MOD.
* Add CTLs for {ADD,MUL,SUB}FP254 operations.
* Refactor the CPU/arithmetic CTL mapping; add some documentation.
* Minor comment fixes.
* Combine addcy CTLs at the expense of repeated constraint evaluation.
* Combine addcy CTLs at the expense of repeated constraint evaluation.
* Merge `*FP254` CTL into main CTL; rename some registers.
* Connect extra argument from CPU in binary ops to facilitate combining with ternary ops.
* Merge modular ops CTL into main CTL.
* Refactor DIV and MOD code into its own module.
* Merge DIV and MOD into arithmetic CTL.
* Clippy.
* Fixes related to merge.
* Simplify register naming.
* Generate u16 BN254 modulus limbs at compile time.
* Clippy.
* Add degree bits ranges for Arithmetic table.
2023-05-11 03:29:06 +10:00
|
|
|
ctl_logic(),
|
|
|
|
|
ctl_memory(),
|
2023-04-14 21:55:44 +08:00
|
|
|
]
|
2022-06-27 10:40:16 -07:00
|
|
|
}
|
|
|
|
|
|
2023-10-30 14:28:24 -04:00
|
|
|
/// `CrossTableLookup` for `ArithmeticStark`, to connect it with the `Cpu` module.
|
Cross-table lookup for arithmetic stark (#905)
* First draft of linking arithmetic Stark into the CTL mechanism.
* Handle {ADD,SUB,MUL}FP254 operations explicitly in `modular.rs`.
* Adjust argument order; add tests.
* Add CTLs for ADD, MUL, SUB, LT and GT.
* Add CTLs for {ADD,MUL,SUB}MOD, DIV and MOD.
* Add CTLs for {ADD,MUL,SUB}FP254 operations.
* Refactor the CPU/arithmetic CTL mapping; add some documentation.
* Minor comment fixes.
* Combine addcy CTLs at the expense of repeated constraint evaluation.
* Combine addcy CTLs at the expense of repeated constraint evaluation.
* Merge `*FP254` CTL into main CTL; rename some registers.
* Connect extra argument from CPU in binary ops to facilitate combining with ternary ops.
* Merge modular ops CTL into main CTL.
* Refactor DIV and MOD code into its own module.
* Merge DIV and MOD into arithmetic CTL.
* Clippy.
* Fixes related to merge.
* Simplify register naming.
* Generate u16 BN254 modulus limbs at compile time.
* Clippy.
* Add degree bits ranges for Arithmetic table.
2023-05-11 03:29:06 +10:00
|
|
|
fn ctl_arithmetic<F: Field>() -> CrossTableLookup<F> {
|
|
|
|
|
CrossTableLookup::new(
|
2023-10-05 09:56:56 -04:00
|
|
|
vec![cpu_stark::ctl_arithmetic_base_rows()],
|
Cross-table lookup for arithmetic stark (#905)
* First draft of linking arithmetic Stark into the CTL mechanism.
* Handle {ADD,SUB,MUL}FP254 operations explicitly in `modular.rs`.
* Adjust argument order; add tests.
* Add CTLs for ADD, MUL, SUB, LT and GT.
* Add CTLs for {ADD,MUL,SUB}MOD, DIV and MOD.
* Add CTLs for {ADD,MUL,SUB}FP254 operations.
* Refactor the CPU/arithmetic CTL mapping; add some documentation.
* Minor comment fixes.
* Combine addcy CTLs at the expense of repeated constraint evaluation.
* Combine addcy CTLs at the expense of repeated constraint evaluation.
* Merge `*FP254` CTL into main CTL; rename some registers.
* Connect extra argument from CPU in binary ops to facilitate combining with ternary ops.
* Merge modular ops CTL into main CTL.
* Refactor DIV and MOD code into its own module.
* Merge DIV and MOD into arithmetic CTL.
* Clippy.
* Fixes related to merge.
* Simplify register naming.
* Generate u16 BN254 modulus limbs at compile time.
* Clippy.
* Add degree bits ranges for Arithmetic table.
2023-05-11 03:29:06 +10:00
|
|
|
arithmetic_stark::ctl_arithmetic_rows(),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-30 14:28:24 -04:00
|
|
|
/// `CrossTableLookup` for `BytePackingStark`, to connect it with the `Cpu` module.
|
2023-09-12 14:45:37 -04:00
|
|
|
fn ctl_byte_packing<F: Field>() -> CrossTableLookup<F> {
|
|
|
|
|
let cpu_packing_looking = TableWithColumns::new(
|
|
|
|
|
Table::Cpu,
|
|
|
|
|
cpu_stark::ctl_data_byte_packing(),
|
|
|
|
|
Some(cpu_stark::ctl_filter_byte_packing()),
|
|
|
|
|
);
|
|
|
|
|
let cpu_unpacking_looking = TableWithColumns::new(
|
|
|
|
|
Table::Cpu,
|
|
|
|
|
cpu_stark::ctl_data_byte_unpacking(),
|
|
|
|
|
Some(cpu_stark::ctl_filter_byte_unpacking()),
|
|
|
|
|
);
|
2023-11-15 11:15:14 -05:00
|
|
|
let cpu_push_packing_looking = TableWithColumns::new(
|
|
|
|
|
Table::Cpu,
|
|
|
|
|
cpu_stark::ctl_data_byte_packing_push(),
|
|
|
|
|
Some(cpu_stark::ctl_filter_byte_packing_push()),
|
|
|
|
|
);
|
2023-09-12 14:45:37 -04:00
|
|
|
let byte_packing_looked = TableWithColumns::new(
|
|
|
|
|
Table::BytePacking,
|
|
|
|
|
byte_packing_stark::ctl_looked_data(),
|
|
|
|
|
Some(byte_packing_stark::ctl_looked_filter()),
|
|
|
|
|
);
|
|
|
|
|
CrossTableLookup::new(
|
2023-11-15 11:15:14 -05:00
|
|
|
vec![
|
|
|
|
|
cpu_packing_looking,
|
|
|
|
|
cpu_unpacking_looking,
|
|
|
|
|
cpu_push_packing_looking,
|
|
|
|
|
],
|
2023-09-12 14:45:37 -04:00
|
|
|
byte_packing_looked,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-30 14:28:24 -04:00
|
|
|
/// `CrossTableLookup` for `KeccakStark` inputs, to connect it with the `KeccakSponge` module.
|
|
|
|
|
/// `KeccakStarkSponge` looks into `KeccakStark` to give the inputs of the sponge.
|
|
|
|
|
/// Its consistency with the 'output' CTL is ensured through a timestamp column on the `KeccakStark` side.
|
2023-10-06 15:49:57 -04:00
|
|
|
fn ctl_keccak_inputs<F: Field>() -> CrossTableLookup<F> {
|
2022-12-03 11:21:31 -08:00
|
|
|
let keccak_sponge_looking = TableWithColumns::new(
|
|
|
|
|
Table::KeccakSponge,
|
2023-10-06 15:49:57 -04:00
|
|
|
keccak_sponge_stark::ctl_looking_keccak_inputs(),
|
2022-12-03 11:21:31 -08:00
|
|
|
Some(keccak_sponge_stark::ctl_looking_keccak_filter()),
|
2022-08-14 16:36:07 -07:00
|
|
|
);
|
2022-12-03 11:21:31 -08:00
|
|
|
let keccak_looked = TableWithColumns::new(
|
|
|
|
|
Table::Keccak,
|
2023-10-06 15:49:57 -04:00
|
|
|
keccak_stark::ctl_data_inputs(),
|
|
|
|
|
Some(keccak_stark::ctl_filter_inputs()),
|
|
|
|
|
);
|
|
|
|
|
CrossTableLookup::new(vec![keccak_sponge_looking], keccak_looked)
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-30 14:28:24 -04:00
|
|
|
/// `CrossTableLookup` for `KeccakStark` outputs, to connect it with the `KeccakSponge` module.
|
|
|
|
|
/// `KeccakStarkSponge` looks into `KeccakStark` to give the outputs of the sponge.
|
2023-10-06 15:49:57 -04:00
|
|
|
fn ctl_keccak_outputs<F: Field>() -> CrossTableLookup<F> {
|
|
|
|
|
let keccak_sponge_looking = TableWithColumns::new(
|
|
|
|
|
Table::KeccakSponge,
|
|
|
|
|
keccak_sponge_stark::ctl_looking_keccak_outputs(),
|
|
|
|
|
Some(keccak_sponge_stark::ctl_looking_keccak_filter()),
|
|
|
|
|
);
|
|
|
|
|
let keccak_looked = TableWithColumns::new(
|
|
|
|
|
Table::Keccak,
|
|
|
|
|
keccak_stark::ctl_data_outputs(),
|
|
|
|
|
Some(keccak_stark::ctl_filter_outputs()),
|
2022-08-14 16:36:07 -07:00
|
|
|
);
|
2023-01-03 11:36:42 -08:00
|
|
|
CrossTableLookup::new(vec![keccak_sponge_looking], keccak_looked)
|
2022-06-27 10:40:16 -07:00
|
|
|
}
|
|
|
|
|
|
2023-10-30 14:28:24 -04:00
|
|
|
/// `CrossTableLookup` for `KeccakSpongeStark` to connect it with the `Cpu` module.
|
2022-12-03 11:21:31 -08:00
|
|
|
fn ctl_keccak_sponge<F: Field>() -> CrossTableLookup<F> {
|
|
|
|
|
let cpu_looking = TableWithColumns::new(
|
|
|
|
|
Table::Cpu,
|
|
|
|
|
cpu_stark::ctl_data_keccak_sponge(),
|
|
|
|
|
Some(cpu_stark::ctl_filter_keccak_sponge()),
|
|
|
|
|
);
|
|
|
|
|
let keccak_sponge_looked = TableWithColumns::new(
|
|
|
|
|
Table::KeccakSponge,
|
|
|
|
|
keccak_sponge_stark::ctl_looked_data(),
|
|
|
|
|
Some(keccak_sponge_stark::ctl_looked_filter()),
|
|
|
|
|
);
|
2023-01-03 11:36:42 -08:00
|
|
|
CrossTableLookup::new(vec![cpu_looking], keccak_sponge_looked)
|
2022-08-14 16:36:07 -07:00
|
|
|
}
|
|
|
|
|
|
2023-10-30 14:28:24 -04:00
|
|
|
/// `CrossTableLookup` for `LogicStark` to connect it with the `Cpu` and `KeccakSponge` modules.
|
2022-06-27 10:40:16 -07:00
|
|
|
fn ctl_logic<F: Field>() -> CrossTableLookup<F> {
|
2022-12-03 11:21:31 -08:00
|
|
|
let cpu_looking = TableWithColumns::new(
|
|
|
|
|
Table::Cpu,
|
|
|
|
|
cpu_stark::ctl_data_logic(),
|
|
|
|
|
Some(cpu_stark::ctl_filter_logic()),
|
|
|
|
|
);
|
|
|
|
|
let mut all_lookers = vec![cpu_looking];
|
2022-12-15 13:56:48 -08:00
|
|
|
for i in 0..keccak_sponge_stark::num_logic_ctls() {
|
2022-12-03 11:21:31 -08:00
|
|
|
let keccak_sponge_looking = TableWithColumns::new(
|
|
|
|
|
Table::KeccakSponge,
|
|
|
|
|
keccak_sponge_stark::ctl_looking_logic(i),
|
2022-12-15 13:56:48 -08:00
|
|
|
Some(keccak_sponge_stark::ctl_looking_logic_filter()),
|
2022-12-03 11:21:31 -08:00
|
|
|
);
|
|
|
|
|
all_lookers.push(keccak_sponge_looking);
|
|
|
|
|
}
|
|
|
|
|
let logic_looked =
|
|
|
|
|
TableWithColumns::new(Table::Logic, logic::ctl_data(), Some(logic::ctl_filter()));
|
2023-01-03 11:36:42 -08:00
|
|
|
CrossTableLookup::new(all_lookers, logic_looked)
|
2022-06-27 10:40:16 -07:00
|
|
|
}
|
|
|
|
|
|
2023-10-30 14:28:24 -04:00
|
|
|
/// `CrossTableLookup` for `MemoryStark` to connect it with all the modules which need memory accesses.
|
2022-08-23 17:24:35 -07:00
|
|
|
fn ctl_memory<F: Field>() -> CrossTableLookup<F> {
|
2022-09-22 18:09:23 -07:00
|
|
|
let cpu_memory_code_read = TableWithColumns::new(
|
|
|
|
|
Table::Cpu,
|
|
|
|
|
cpu_stark::ctl_data_code_memory(),
|
|
|
|
|
Some(cpu_stark::ctl_filter_code_memory()),
|
|
|
|
|
);
|
|
|
|
|
let cpu_memory_gp_ops = (0..NUM_GP_CHANNELS).map(|channel| {
|
2022-08-14 16:36:07 -07:00
|
|
|
TableWithColumns::new(
|
|
|
|
|
Table::Cpu,
|
2022-09-22 18:09:23 -07:00
|
|
|
cpu_stark::ctl_data_gp_memory(channel),
|
|
|
|
|
Some(cpu_stark::ctl_filter_gp_memory(channel)),
|
2022-08-14 16:36:07 -07:00
|
|
|
)
|
|
|
|
|
});
|
2023-11-13 11:03:50 -05:00
|
|
|
let cpu_push_write_ops = TableWithColumns::new(
|
|
|
|
|
Table::Cpu,
|
|
|
|
|
cpu_stark::ctl_data_partial_memory::<F>(),
|
|
|
|
|
Some(cpu_stark::ctl_filter_partial_memory()),
|
|
|
|
|
);
|
2022-12-03 11:21:31 -08:00
|
|
|
let keccak_sponge_reads = (0..KECCAK_RATE_BYTES).map(|i| {
|
2022-08-14 16:36:07 -07:00
|
|
|
TableWithColumns::new(
|
2022-12-03 11:21:31 -08:00
|
|
|
Table::KeccakSponge,
|
|
|
|
|
keccak_sponge_stark::ctl_looking_memory(i),
|
|
|
|
|
Some(keccak_sponge_stark::ctl_looking_memory_filter(i)),
|
2022-08-14 16:36:07 -07:00
|
|
|
)
|
|
|
|
|
});
|
2023-09-12 14:45:37 -04:00
|
|
|
let byte_packing_ops = (0..32).map(|i| {
|
|
|
|
|
TableWithColumns::new(
|
|
|
|
|
Table::BytePacking,
|
|
|
|
|
byte_packing_stark::ctl_looking_memory(i),
|
|
|
|
|
Some(byte_packing_stark::ctl_looking_memory_filter(i)),
|
|
|
|
|
)
|
|
|
|
|
});
|
2022-09-22 18:09:23 -07:00
|
|
|
let all_lookers = iter::once(cpu_memory_code_read)
|
|
|
|
|
.chain(cpu_memory_gp_ops)
|
2023-11-13 11:03:50 -05:00
|
|
|
.chain(iter::once(cpu_push_write_ops))
|
2022-12-03 11:21:31 -08:00
|
|
|
.chain(keccak_sponge_reads)
|
2023-09-12 14:45:37 -04:00
|
|
|
.chain(byte_packing_ops)
|
2022-08-14 16:36:07 -07:00
|
|
|
.collect();
|
2022-12-03 11:21:31 -08:00
|
|
|
let memory_looked = TableWithColumns::new(
|
|
|
|
|
Table::Memory,
|
|
|
|
|
memory_stark::ctl_data(),
|
|
|
|
|
Some(memory_stark::ctl_filter()),
|
|
|
|
|
);
|
2023-01-03 11:36:42 -08:00
|
|
|
CrossTableLookup::new(all_lookers, memory_looked)
|
2022-05-06 17:22:30 +02:00
|
|
|
}
|