Skip to content

Commit

Permalink
Merge branch 'develop' into feat/feature_gate_chain
Browse files Browse the repository at this point in the history
  • Loading branch information
Nashtare committed Sep 6, 2024
2 parents 2df059f + 7f7ce75 commit 07224e1
Show file tree
Hide file tree
Showing 80 changed files with 2,107 additions and 748 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ LOGIC_CIRCUIT_SIZE=4..21
MEMORY_CIRCUIT_SIZE=17..24
MEMORY_BEFORE_CIRCUIT_SIZE=16..23
MEMORY_AFTER_CIRCUIT_SIZE=7..23
POSEIDON_CIRCUIT_SIZE=4..25
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -239,5 +239,8 @@ jobs:
- name: Run cargo clippy
run: cargo clippy --all-targets -- -D warnings -A incomplete-features

- name: Run cargo clippy (with `cdk_erigon` flag)
run: cargo clippy --all-features --all-targets --features cdk_erigon -- -D warnings -A incomplete-features

- name: Rustdoc
run: cargo doc --all
113 changes: 70 additions & 43 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion evm_arithmetization/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ serde-big-array = { workspace = true }

# Local dependencies
mpt_trie = { workspace = true }
smt_trie = { workspace = true, optional = true }
zk_evm_proc_macro = { workspace = true }

[dev-dependencies]
Expand All @@ -59,7 +60,7 @@ ripemd = { workspace = true }
default = ["eth_mainnet"]
asmtools = ["hex"]
polygon_pos = []
cdk_erigon = []
cdk_erigon = ["smt_trie"]
eth_mainnet = []

[[bin]]
Expand Down
75 changes: 71 additions & 4 deletions evm_arithmetization/src/all_stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ use crate::logic::LogicStark;
use crate::memory::memory_stark::MemoryStark;
use crate::memory::memory_stark::{self, ctl_context_pruning_looking};
use crate::memory_continuation::memory_continuation_stark::{self, MemoryContinuationStark};
#[cfg(feature = "cdk_erigon")]
use crate::poseidon::{
columns::POSEIDON_SPONGE_RATE,
poseidon_stark::{self, PoseidonStark, FELT_MAX_BYTES},
};

/// Structure containing all STARKs and the cross-table lookups.
#[derive(Clone)]
Expand All @@ -38,6 +43,8 @@ pub struct AllStark<F: RichField + Extendable<D>, const D: usize> {
pub(crate) memory_stark: MemoryStark<F, D>,
pub(crate) mem_before_stark: MemoryContinuationStark<F, D>,
pub(crate) mem_after_stark: MemoryContinuationStark<F, D>,
#[cfg(feature = "cdk_erigon")]
pub(crate) poseidon_stark: PoseidonStark<F, D>,
pub(crate) cross_table_lookups: Vec<CrossTableLookup<F>>,
}

Expand All @@ -55,6 +62,8 @@ impl<F: RichField + Extendable<D>, const D: usize> Default for AllStark<F, D> {
memory_stark: MemoryStark::default(),
mem_before_stark: MemoryContinuationStark::default(),
mem_after_stark: MemoryContinuationStark::default(),
#[cfg(feature = "cdk_erigon")]
poseidon_stark: PoseidonStark::default(),
cross_table_lookups: all_cross_table_lookups(),
}
}
Expand All @@ -72,6 +81,8 @@ impl<F: RichField + Extendable<D>, const D: usize> AllStark<F, D> {
self.memory_stark.num_lookup_helper_columns(config),
self.mem_before_stark.num_lookup_helper_columns(config),
self.mem_after_stark.num_lookup_helper_columns(config),
#[cfg(feature = "cdk_erigon")]
self.poseidon_stark.num_lookup_helper_columns(config),
]
}
}
Expand All @@ -90,6 +101,8 @@ pub enum Table {
Memory = 6,
MemBefore = 7,
MemAfter = 8,
#[cfg(feature = "cdk_erigon")]
Poseidon = 9,
}

impl Deref for Table {
Expand All @@ -98,12 +111,20 @@ impl Deref for Table {
fn deref(&self) -> &Self::Target {
// Hacky way to implement `Deref` for `Table` so that we don't have to
// call `Table::Foo as usize`, but perhaps too ugly to be worth it.
[&0, &1, &2, &3, &4, &5, &6, &7, &8][*self as TableIdx]
#[cfg(not(feature = "cdk_erigon"))]
return [&0, &1, &2, &3, &4, &5, &6, &7, &8][*self as TableIdx];

#[cfg(feature = "cdk_erigon")]
[&0, &1, &2, &3, &4, &5, &6, &7, &8, &9][*self as TableIdx]
}
}

/// Number of STARK tables.
pub(crate) const NUM_TABLES: usize = Table::MemAfter as usize + 1;
pub const NUM_TABLES: usize = if cfg!(feature = "cdk_erigon") {
Table::MemAfter as usize + 2
} else {
Table::MemAfter as usize + 1
};

impl Table {
/// Returns all STARK table indices.
Expand All @@ -118,6 +139,8 @@ impl Table {
Self::Memory,
Self::MemBefore,
Self::MemAfter,
#[cfg(feature = "cdk_erigon")]
Self::Poseidon,
]
}
}
Expand All @@ -135,6 +158,12 @@ pub(crate) fn all_cross_table_lookups<F: Field>() -> Vec<CrossTableLookup<F>> {
ctl_mem_before(),
ctl_mem_after(),
ctl_context_pruning(),
#[cfg(feature = "cdk_erigon")]
ctl_poseidon_simple(),
#[cfg(feature = "cdk_erigon")]
ctl_poseidon_general_input(),
#[cfg(feature = "cdk_erigon")]
ctl_poseidon_general_output(),
]
}

Expand Down Expand Up @@ -307,6 +336,16 @@ fn ctl_memory<F: Field>() -> CrossTableLookup<F> {
memory_continuation_stark::ctl_data_memory(),
memory_continuation_stark::ctl_filter(),
);

#[cfg(feature = "cdk_erigon")]
let poseidon_general_reads = (0..FELT_MAX_BYTES * POSEIDON_SPONGE_RATE).map(|i| {
TableWithColumns::new(
*Table::Poseidon,
poseidon_stark::ctl_looking_memory(i),
poseidon_stark::ctl_looking_memory_filter(),
)
});

let all_lookers = vec![
cpu_memory_code_read,
cpu_push_write_ops,
Expand All @@ -317,8 +356,12 @@ fn ctl_memory<F: Field>() -> CrossTableLookup<F> {
.chain(cpu_memory_gp_ops)
.chain(keccak_sponge_reads)
.chain(byte_packing_ops)
.chain(iter::once(mem_before_ops))
.collect();
.chain(iter::once(mem_before_ops));

#[cfg(feature = "cdk_erigon")]
let all_lookers = all_lookers.chain(poseidon_general_reads);

let all_lookers = all_lookers.collect();
let memory_looked = TableWithColumns::new(
*Table::Memory,
memory_stark::ctl_data(),
Expand Down Expand Up @@ -368,3 +411,27 @@ fn ctl_mem_after<F: Field>() -> CrossTableLookup<F> {
);
CrossTableLookup::new(all_lookers, mem_after_looked)
}

#[cfg(feature = "cdk_erigon")]
fn ctl_poseidon_simple<F: Field>() -> CrossTableLookup<F> {
CrossTableLookup::new(
vec![cpu_stark::ctl_poseidon_simple_op()],
poseidon_stark::ctl_looked_simple_op(),
)
}

#[cfg(feature = "cdk_erigon")]
fn ctl_poseidon_general_input<F: Field>() -> CrossTableLookup<F> {
CrossTableLookup::new(
vec![cpu_stark::ctl_poseidon_general_input()],
poseidon_stark::ctl_looked_general_input(),
)
}

#[cfg(feature = "cdk_erigon")]
fn ctl_poseidon_general_output<F: Field>() -> CrossTableLookup<F> {
CrossTableLookup::new(
vec![cpu_stark::ctl_poseidon_general_output()],
poseidon_stark::ctl_looked_general_output(),
)
}
Loading

0 comments on commit 07224e1

Please sign in to comment.