plonky2/evm/src/memory/columns.rs

38 lines
1.6 KiB
Rust
Raw Normal View History

//! Memory registers.
2022-06-13 14:37:29 -07:00
use crate::memory::VALUE_LIMBS;
2022-07-12 14:54:36 -07:00
// Columns for memory operations, ordered by (addr, timestamp).
2022-08-23 17:24:35 -07:00
/// 1 if this is an actual memory operation, or 0 if it's a padding row.
pub(crate) const FILTER: usize = 0;
pub(crate) const TIMESTAMP: usize = FILTER + 1;
pub(crate) const IS_READ: usize = TIMESTAMP + 1;
pub(crate) const ADDR_CONTEXT: usize = IS_READ + 1;
pub(crate) const ADDR_SEGMENT: usize = ADDR_CONTEXT + 1;
pub(crate) const ADDR_VIRTUAL: usize = ADDR_SEGMENT + 1;
// Eight 32-bit limbs hold a total of 256 bits.
// If a value represents an integer, it is little-endian encoded.
2022-06-17 16:52:42 -07:00
const VALUE_START: usize = ADDR_VIRTUAL + 1;
pub(crate) const fn value_limb(i: usize) -> usize {
debug_assert!(i < VALUE_LIMBS);
VALUE_START + i
2022-06-07 14:40:42 -07:00
}
// Flags to indicate whether this part of the address differs from the next row,
// and the previous parts do not differ.
// That is, e.g., `SEGMENT_FIRST_CHANGE` is `F::ONE` iff `ADDR_CONTEXT` is the same in this
// row and the next, but `ADDR_SEGMENT` is not.
pub(crate) const CONTEXT_FIRST_CHANGE: usize = VALUE_START + VALUE_LIMBS;
pub(crate) const SEGMENT_FIRST_CHANGE: usize = CONTEXT_FIRST_CHANGE + 1;
pub(crate) const VIRTUAL_FIRST_CHANGE: usize = SEGMENT_FIRST_CHANGE + 1;
2022-06-07 14:40:42 -07:00
// We use a range check to enforce the ordering.
pub(crate) const RANGE_CHECK: usize = VIRTUAL_FIRST_CHANGE + 1;
/// The counter column (used for the range check) starts from 0 and increments.
pub(crate) const COUNTER: usize = RANGE_CHECK + 1;
/// The frequencies column used in logUp.
2023-02-13 15:58:26 +01:00
pub(crate) const FREQUENCIES: usize = COUNTER + 1;
2023-02-13 15:58:26 +01:00
pub(crate) const NUM_COLUMNS: usize = FREQUENCIES + 1;