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

Implement Polygon Hermez type2 SMT #34

Merged
merged 34 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
030477c
Working with dummy hash
wborgeaud Oct 17, 2023
1f50afd
Use keccak
wborgeaud Oct 17, 2023
8cf5563
Add account
wborgeaud Oct 17, 2023
1532402
Clippy
wborgeaud Oct 17, 2023
c57145e
Support storage trie
wborgeaud Oct 18, 2023
f53993d
Use remaining key and clean
wborgeaud Oct 23, 2023
53f7538
Write pointer to leaf data in serialization
wborgeaud Oct 23, 2023
77f0953
Minor
wborgeaud Oct 27, 2023
aa7313c
Comments
wborgeaud Oct 27, 2023
c8eae85
Cleaning
wborgeaud Feb 9, 2024
6c19943
Cleaning
wborgeaud Feb 10, 2024
a507641
readme
wborgeaud Feb 10, 2024
603836e
Fix plonky2 dep
wborgeaud Feb 10, 2024
826e594
Fix dep
wborgeaud Feb 10, 2024
c50037a
minor
wborgeaud Feb 12, 2024
17e94ea
Remove dbg
wborgeaud Feb 14, 2024
8d7ccc9
Squashed 'evm_arithmetization/' changes from d547f8d5..5ec32fcb
Nashtare Feb 14, 2024
25fabd3
Bump deps
Nashtare Feb 14, 2024
77721e2
Merge commit '8d7ccc9042f6df486a7b0f1c963ba296e3edec1c' into type2/he…
Nashtare Feb 14, 2024
2cf433e
Add 'smt-trie/' from commit '25fabd31f0da4813b2adbd16c68cf0fbca4c6ebc'
Nashtare Feb 14, 2024
d1604de
Make smt_trie a local dependency
Nashtare Feb 14, 2024
a563687
fmt
Nashtare Feb 14, 2024
0e22c5f
Add temporary bindings to old dependencies
Nashtare Feb 14, 2024
b84598b
Implement recursive table chain for Poseidon
Nashtare Feb 14, 2024
d14ba96
Merge remote-tracking branch 'main' into type2/hermez
Nashtare Feb 26, 2024
63b9e08
Bring latest fixes
Nashtare Feb 26, 2024
9396725
More missing fixes
Nashtare Feb 26, 2024
30da68c
More
Nashtare Feb 26, 2024
4f89287
PR feedback
wborgeaud Mar 25, 2024
9e89a54
DUP 0xffffffff
wborgeaud Mar 27, 2024
56ed5dd
PR feedback
wborgeaud Mar 27, 2024
c227bbd
PR feedback
wborgeaud Mar 27, 2024
21fe81d
AND -> MOD
wborgeaud Mar 27, 2024
3afc5a2
Merge branch 'develop' into type2/hermez
Nashtare Apr 3, 2024
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
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
[workspace]
members = ["mpt_trie", "proof_gen", "trace_decoder", "evm_arithmetization"]
members = [
"evm_arithmetization",
"mpt_trie",
"proof_gen",
"smt_trie",
"trace_decoder"
]
resolver = "2"

[workspace.dependencies]
Expand Down
1 change: 1 addition & 0 deletions evm_arithmetization/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ serde_json = { workspace = true }

# Local dependencies
mpt_trie = { version = "0.1.0", path = "../mpt_trie" }
smt_trie = { version = "0.1.0", path = "../smt_trie" }

[target.'cfg(not(target_env = "msvc"))'.dependencies]
jemallocator = "0.5.0"
Expand Down
19 changes: 17 additions & 2 deletions evm_arithmetization/src/all_stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ use crate::logic;
use crate::logic::LogicStark;
use crate::memory::memory_stark;
use crate::memory::memory_stark::MemoryStark;
use crate::poseidon::poseidon_stark;
use crate::poseidon::poseidon_stark::PoseidonStark;

/// Structure containing all STARKs and the cross-table lookups.
#[derive(Clone)]
Expand All @@ -34,6 +36,7 @@ pub struct AllStark<F: RichField + Extendable<D>, const D: usize> {
pub(crate) keccak_sponge_stark: KeccakSpongeStark<F, D>,
pub(crate) logic_stark: LogicStark<F, D>,
pub(crate) memory_stark: MemoryStark<F, D>,
pub(crate) poseidon_stark: PoseidonStark<F, D>,
pub(crate) cross_table_lookups: Vec<CrossTableLookup<F>>,
}

Expand All @@ -49,6 +52,7 @@ impl<F: RichField + Extendable<D>, const D: usize> Default for AllStark<F, D> {
keccak_sponge_stark: KeccakSpongeStark::default(),
logic_stark: LogicStark::default(),
memory_stark: MemoryStark::default(),
poseidon_stark: PoseidonStark::default(),
cross_table_lookups: all_cross_table_lookups(),
}
}
Expand All @@ -64,6 +68,7 @@ impl<F: RichField + Extendable<D>, const D: usize> AllStark<F, D> {
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),
0,
]
}
}
Expand All @@ -80,6 +85,7 @@ pub enum Table {
KeccakSponge = 4,
Logic = 5,
Memory = 6,
Poseidon = 7,
}

impl Deref for Table {
Expand All @@ -88,12 +94,12 @@ 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][*self as TableIdx]
[&0, &1, &2, &3, &4, &5, &6, &7][*self as TableIdx]
}
}

/// Number of STARK tables.
pub(crate) const NUM_TABLES: usize = Table::Memory as usize + 1;
pub(crate) const NUM_TABLES: usize = Table::Poseidon as usize + 1;

impl Table {
/// Returns all STARK table indices.
Expand All @@ -106,6 +112,7 @@ impl Table {
Self::KeccakSponge,
Self::Logic,
Self::Memory,
Self::Poseidon,
]
}
}
Expand All @@ -120,6 +127,7 @@ pub(crate) fn all_cross_table_lookups<F: Field>() -> Vec<CrossTableLookup<F>> {
ctl_keccak_outputs(),
ctl_logic(),
ctl_memory(),
ctl_poseidon(),
]
}

Expand Down Expand Up @@ -306,3 +314,10 @@ fn ctl_memory<F: Field>() -> CrossTableLookup<F> {
);
CrossTableLookup::new(all_lookers, memory_looked)
}

fn ctl_poseidon<F: Field>() -> CrossTableLookup<F> {
CrossTableLookup::new(
vec![cpu_stark::ctl_poseidon()],
poseidon_stark::ctl_looked(),
)
}
1 change: 1 addition & 0 deletions evm_arithmetization/src/cpu/columns/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub(crate) struct OpsColumnsView<T: Copy> {
pub shift: T,
/// Combines JUMPDEST and KECCAK_GENERAL flags.
pub jumpdest_keccak_general: T,
pub poseidon: T,
/// Combines JUMP and JUMPI flags.
pub jumps: T,
/// Combines PUSH and PROVER_INPUT flags.
Expand Down
1 change: 1 addition & 0 deletions evm_arithmetization/src/cpu/contextops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const KEEPS_CONTEXT: OpsColumnsView<bool> = OpsColumnsView {
not_pop: true,
shift: true,
jumpdest_keccak_general: true,
poseidon: true,
push_prover_input: true,
jumps: true,
pc_push0: true,
Expand Down
3 changes: 2 additions & 1 deletion evm_arithmetization/src/cpu/control_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use starky::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsume
use crate::cpu::columns::{CpuColumnsView, COL_MAP};
use crate::cpu::kernel::aggregator::KERNEL;

const NATIVE_INSTRUCTIONS: [usize; 12] = [
const NATIVE_INSTRUCTIONS: [usize; 13] = [
COL_MAP.op.binary_op,
COL_MAP.op.ternary_op,
COL_MAP.op.fp254_op,
Expand All @@ -17,6 +17,7 @@ const NATIVE_INSTRUCTIONS: [usize; 12] = [
COL_MAP.op.not_pop,
COL_MAP.op.shift,
COL_MAP.op.jumpdest_keccak_general,
COL_MAP.op.poseidon,
// Not PROVER_INPUT: it is dealt with manually below.
// not JUMPS (possible need to jump)
COL_MAP.op.pc_push0,
Expand Down
25 changes: 25 additions & 0 deletions evm_arithmetization/src/cpu/cpu_stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,31 @@ pub(crate) fn ctl_filter_set_context<F: Field>() -> Filter<F> {
)
}

/// Returns the `TableWithColumns` for the CPU rows calling POSEIDON.
pub(crate) fn ctl_poseidon<F: Field>() -> TableWithColumns<F> {
let mut columns = Vec::new();
for channel in 0..3 {
for i in 0..VALUE_LIMBS / 2 {
columns.push(Column::linear_combination([
(COL_MAP.mem_channels[channel].value[2 * i], F::ONE),
(
COL_MAP.mem_channels[channel].value[2 * i + 1],
F::from_canonical_u64(1 << 32),
),
]));
}
}
columns.extend(Column::singles_next_row(COL_MAP.mem_channels[0].value));
// res.extend(Column::singles(COL_MAP.mem_channels[1].value));
// res.extend(Column::singles(COL_MAP.mem_channels[2].value));
// res
TableWithColumns::new(
*Table::Cpu,
columns,
Some(Filter::new_simple(Column::single(COL_MAP.op.poseidon))),
)
}

/// Disable the specified memory channels.
/// Since channel 0 contains the top of the stack and is handled specially,
/// channels to disable are 1, 2 or both. All cases can be expressed as a vec.
Expand Down
3 changes: 2 additions & 1 deletion evm_arithmetization/src/cpu/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ use crate::cpu::columns::{CpuColumnsView, COL_MAP};
/// Note: invalid opcodes are not represented here. _Any_ opcode is permitted to
/// decode to `is_invalid`. The kernel then verifies that the opcode was
/// _actually_ invalid.
const OPCODES: [(u8, usize, bool, usize); 5] = [
const OPCODES: [(u8, usize, bool, usize); 6] = [
// (start index of block, number of top bits to check (log2), kernel-only, flag column)
// ADD, MUL, SUB, DIV, MOD, LT, GT and BYTE flags are handled partly manually here, and partly
// through the Arithmetic table CTL. ADDMOD, MULMOD and SUBMOD flags are handled partly
// manually here, and partly through the Arithmetic table CTL. FP254 operation flags are
// handled partly manually here, and partly through the Arithmetic table CTL.
(0x14, 1, false, COL_MAP.op.eq_iszero),
(0x22, 0, true, COL_MAP.op.poseidon),
// AND, OR and XOR flags are handled partly manually here, and partly through the Logic table
// CTL. NOT and POP are handled manually here.
// SHL and SHR flags are handled partly manually here, and partly through the Logic table CTL.
Expand Down
5 changes: 3 additions & 2 deletions evm_arithmetization/src/cpu/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ const SIMPLE_OPCODES: OpsColumnsView<Option<u32>> = OpsColumnsView {
not_pop: None, // This is handled manually below
shift: G_VERYLOW,
jumpdest_keccak_general: None, // This is handled manually below.
push_prover_input: None, // This is handled manually below.
jumps: None, // Combined flag handled separately.
poseidon: KERNEL_ONLY_INSTR,
push_prover_input: None, // This is handled manually below.
jumps: None, // Combined flag handled separately.
pc_push0: G_BASE,
dup_swap: G_VERYLOW,
context_op: KERNEL_ONLY_INSTR,
Expand Down
6 changes: 6 additions & 0 deletions evm_arithmetization/src/cpu/kernel/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ pub(crate) fn combined_kernel() -> Kernel {
include_str!("asm/mpt/storage/storage_read.asm"),
include_str!("asm/mpt/storage/storage_write.asm"),
include_str!("asm/mpt/util.asm"),
include_str!("asm/smt/delete.asm"),
include_str!("asm/smt/hash.asm"),
include_str!("asm/smt/insert.asm"),
include_str!("asm/smt/keys.asm"),
include_str!("asm/smt/read.asm"),
include_str!("asm/smt/utils.asm"),
include_str!("asm/rlp/decode.asm"),
include_str!("asm/rlp/encode.asm"),
include_str!("asm/rlp/encode_rlp_scalar.asm"),
Expand Down
Loading