Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move byte packing / unpacking to a distinct table #1212

Merged
merged 41 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
65e4220
Duplicate Memory trace into BytePacking one
Nashtare Aug 28, 2023
78c1333
Add mload_32bytes instruction
Nashtare Aug 28, 2023
bba1998
Use dedicated ops for byte packing trace
Nashtare Aug 28, 2023
eb15361
Change witness generation to reduce memory reads for MLOAD_32BYTES
Nashtare Aug 29, 2023
6844573
Remove segments
Nashtare Aug 29, 2023
d82066e
Fix stack
Nashtare Aug 29, 2023
0bb094f
Fix extra product when fixing CTL for byte_packing
Nashtare Aug 29, 2023
bb2b04b
Write output value in trace
Nashtare Aug 29, 2023
c1ce80d
Add constraints for BYTE_PACKING table
Nashtare Aug 29, 2023
862c1df
Add recursive constraints for BYTE_PACKING table
Nashtare Aug 29, 2023
99ed5f0
Fix constraints
Nashtare Aug 30, 2023
f72f901
Add address in trace and constraints
Nashtare Aug 30, 2023
06eaf71
Add timestamp and batch inputs into BytePackingOp struct
Nashtare Aug 30, 2023
5c410ef
Add extra column
Nashtare Aug 31, 2023
f7fe9ef
Fix BytePackingStark CTL
Nashtare Aug 31, 2023
bbabe55
Tiny fix in witness generation
Nashtare Sep 1, 2023
fcb6920
Fix the Memory CTL
Nashtare Sep 1, 2023
e88744a
Add constraints for the new columns
Nashtare Sep 1, 2023
3d9be52
Remove 1 column
Nashtare Sep 1, 2023
017c29f
Remove limb columns
Nashtare Sep 1, 2023
0193626
Fix
Nashtare Sep 1, 2023
3e0a58e
Fix recursive circuit of BytePackingTable
Nashtare Sep 2, 2023
5827e84
Fix constraints
Nashtare Sep 2, 2023
f3e84c1
Fix endianness
Nashtare Sep 2, 2023
03d5614
Add MSTORE_32BYTES instruction and move decomposition to packing table
Nashtare Sep 5, 2023
2aa699a
Add missing constraint
Nashtare Sep 5, 2023
79a7a1c
Add range-check for all bytes
Nashtare Sep 5, 2023
d10b75b
Add extra constraint
Nashtare Sep 6, 2023
6c65949
Cleanup
Nashtare Sep 6, 2023
3128c0e
Remove REMAINING_LEN column
Nashtare Sep 6, 2023
ef420a3
Add corresponding implementations in interpreter
Nashtare Sep 6, 2023
41ddd55
Fix recursive version
Nashtare Sep 6, 2023
f350c22
Remove debug assertion because of CI
Nashtare Sep 6, 2023
e2ca182
Remove FILTER column
Nashtare Sep 6, 2023
ce47858
Update new test from rebasing
Nashtare Sep 6, 2023
e526987
Reorder STARK modules to match TraceCheckPoint ordering
Nashtare Sep 6, 2023
83dc90d
Merge branch 'main' of https://github.com/mir-protocol/plonky2 into p…
Nashtare Sep 9, 2023
1479ee3
Address comments
Nashtare Sep 12, 2023
a13f509
Pacify clippy
Nashtare Sep 12, 2023
ce09a63
Add documentation to the packing module
Nashtare Sep 12, 2023
e9a837b
Fix doctest
Nashtare Sep 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 43 additions & 5 deletions evm/src/all_stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use plonky2::hash::hash_types::RichField;

use crate::arithmetic::arithmetic_stark;
use crate::arithmetic::arithmetic_stark::ArithmeticStark;
use crate::byte_packing::byte_packing_stark::{self, BytePackingStark};
use crate::config::StarkConfig;
use crate::cpu::cpu_stark;
use crate::cpu::cpu_stark::CpuStark;
Expand All @@ -25,6 +26,7 @@ use crate::stark::Stark;
#[derive(Clone)]
pub struct AllStark<F: RichField + Extendable<D>, const D: usize> {
pub arithmetic_stark: ArithmeticStark<F, D>,
pub byte_packing_stark: BytePackingStark<F, D>,
pub cpu_stark: CpuStark<F, D>,
pub keccak_stark: KeccakStark<F, D>,
pub keccak_sponge_stark: KeccakSpongeStark<F, D>,
Expand All @@ -37,6 +39,7 @@ impl<F: RichField + Extendable<D>, const D: usize> Default for AllStark<F, D> {
fn default() -> Self {
Self {
arithmetic_stark: ArithmeticStark::default(),
byte_packing_stark: BytePackingStark::default(),
cpu_stark: CpuStark::default(),
keccak_stark: KeccakStark::default(),
keccak_sponge_stark: KeccakSpongeStark::default(),
Expand All @@ -51,6 +54,7 @@ impl<F: RichField + Extendable<D>, const D: usize> AllStark<F, D> {
pub(crate) fn nums_permutation_zs(&self, config: &StarkConfig) -> [usize; NUM_TABLES] {
[
self.arithmetic_stark.num_permutation_batches(config),
self.byte_packing_stark.num_permutation_batches(config),
self.cpu_stark.num_permutation_batches(config),
self.keccak_stark.num_permutation_batches(config),
self.keccak_sponge_stark.num_permutation_batches(config),
Expand All @@ -62,6 +66,7 @@ impl<F: RichField + Extendable<D>, const D: usize> AllStark<F, D> {
pub(crate) fn permutation_batch_sizes(&self) -> [usize; NUM_TABLES] {
[
self.arithmetic_stark.permutation_batch_size(),
self.byte_packing_stark.permutation_batch_size(),
self.cpu_stark.permutation_batch_size(),
self.keccak_stark.permutation_batch_size(),
self.keccak_sponge_stark.permutation_batch_size(),
Expand All @@ -74,11 +79,12 @@ impl<F: RichField + Extendable<D>, const D: usize> AllStark<F, D> {
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum Table {
Arithmetic = 0,
Cpu = 1,
Keccak = 2,
KeccakSponge = 3,
Logic = 4,
Memory = 5,
BytePacking = 1,
Cpu = 2,
Keccak = 3,
KeccakSponge = 4,
Logic = 5,
Memory = 6,
}

pub(crate) const NUM_TABLES: usize = Table::Memory as usize + 1;
Expand All @@ -87,6 +93,7 @@ impl Table {
pub(crate) fn all() -> [Self; NUM_TABLES] {
[
Self::Arithmetic,
Self::BytePacking,
Self::Cpu,
Self::Keccak,
Self::KeccakSponge,
Expand All @@ -99,6 +106,7 @@ impl Table {
pub(crate) fn all_cross_table_lookups<F: Field>() -> Vec<CrossTableLookup<F>> {
vec![
ctl_arithmetic(),
ctl_byte_packing(),
ctl_keccak_sponge(),
ctl_keccak(),
ctl_logic(),
Expand All @@ -116,6 +124,28 @@ fn ctl_arithmetic<F: Field>() -> CrossTableLookup<F> {
)
}

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()),
);
let byte_packing_looked = TableWithColumns::new(
Table::BytePacking,
byte_packing_stark::ctl_looked_data(),
Some(byte_packing_stark::ctl_looked_filter()),
);
CrossTableLookup::new(
vec![cpu_packing_looking, cpu_unpacking_looking],
byte_packing_looked,
)
}

fn ctl_keccak<F: Field>() -> CrossTableLookup<F> {
let keccak_sponge_looking = TableWithColumns::new(
Table::KeccakSponge,
Expand Down Expand Up @@ -184,9 +214,17 @@ fn ctl_memory<F: Field>() -> CrossTableLookup<F> {
Some(keccak_sponge_stark::ctl_looking_memory_filter(i)),
)
});
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)),
)
});
let all_lookers = iter::once(cpu_memory_code_read)
.chain(cpu_memory_gp_ops)
.chain(keccak_sponge_reads)
.chain(byte_packing_ops)
.collect();
let memory_looked = TableWithColumns::new(
Table::Memory,
Expand Down
Loading
Loading