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

38 lines
1.4 KiB
Rust
Raw Normal View History

/// These metadata fields contain VM state specific to a particular context.
#[derive(Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd, Debug)]
pub(crate) enum ContextMetadata {
/// The ID of the context which created this one.
ParentContext = 0,
/// The program counter to return to when we return to the parent context.
ParentProgramCounter = 1,
2022-08-01 21:21:35 -07:00
/// If we're in a system call, this holds the userspace program counter to return to.
UserspaceProgramCounter = 2,
CalldataSize = 3,
ReturndataSize = 4,
}
impl ContextMetadata {
2022-08-01 21:21:35 -07:00
pub(crate) const COUNT: usize = 5;
pub(crate) fn all() -> [Self; Self::COUNT] {
[
Self::ParentContext,
Self::ParentProgramCounter,
2022-08-01 21:21:35 -07:00
Self::UserspaceProgramCounter,
Self::CalldataSize,
Self::ReturndataSize,
]
}
/// The variable name that gets passed into kernel assembly code.
pub(crate) fn var_name(&self) -> &'static str {
match self {
ContextMetadata::ParentContext => "CTX_METADATA_PARENT_CONTEXT",
ContextMetadata::ParentProgramCounter => "CTX_METADATA_PARENT_PC",
2022-08-01 21:21:35 -07:00
ContextMetadata::UserspaceProgramCounter => "CTX_METADATA_USERSPACE_PC",
ContextMetadata::CalldataSize => "CTX_METADATA_CALLDATA_SIZE",
ContextMetadata::ReturndataSize => "CTX_METADATA_RETURNDATA_SIZE",
}
}
}