plonky2/evm/src/cpu/kernel/global_metadata.rs

30 lines
1.1 KiB
Rust
Raw Normal View History

/// These metadata fields contain global VM state, stored in the `Segment::Metadata` segment of the
/// kernel's context (which is zero).
#[derive(Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd, Debug)]
pub(crate) enum GlobalMetadata {
/// The largest context ID that has been used so far in this execution. Tracking this allows us
/// give each new context a unique ID, so that its memory will be zero-initialized.
LargestContext = 0,
2022-08-03 13:40:43 -07:00
/// The address of the sender of the transaction.
Origin = 1,
/// The size of active memory, in bytes.
MemorySize = 2,
}
impl GlobalMetadata {
2022-08-03 13:40:43 -07:00
pub(crate) const COUNT: usize = 3;
pub(crate) fn all() -> [Self; Self::COUNT] {
2022-08-03 13:40:43 -07:00
[Self::LargestContext, Self::Origin, Self::MemorySize]
}
/// The variable name that gets passed into kernel assembly code.
pub(crate) fn var_name(&self) -> &'static str {
match self {
GlobalMetadata::LargestContext => "GLOBAL_METADATA_LARGEST_CONTEXT",
2022-08-03 13:40:43 -07:00
GlobalMetadata::Origin => "GLOBAL_METADATA_ORIGIN",
GlobalMetadata::MemorySize => "GLOBAL_METADATA_MEMORY_SIZE",
}
}
}