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

172 lines
7.5 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 size of active memory, in bytes.
2023-03-18 09:29:31 -07:00
MemorySize = 1,
/// The size of the `TrieData` segment, in bytes. In other words, the next address available for
/// appending additional trie data.
2023-03-18 09:29:31 -07:00
TrieDataSize = 2,
/// The size of the `TrieData` segment, in bytes. In other words, the next address available for
/// appending additional trie data.
RlpDataSize = 3,
/// A pointer to the root of the state trie within the `TrieData` buffer.
StateTrieRoot = 4,
/// A pointer to the root of the transaction trie within the `TrieData` buffer.
TransactionTrieRoot = 5,
/// A pointer to the root of the receipt trie within the `TrieData` buffer.
ReceiptTrieRoot = 6,
2022-08-25 12:24:22 -07:00
// The root digests of each Merkle trie before these transactions.
StateTrieRootDigestBefore = 7,
TransactionTrieRootDigestBefore = 8,
ReceiptTrieRootDigestBefore = 9,
2022-08-25 12:24:22 -07:00
// The root digests of each Merkle trie after these transactions.
StateTrieRootDigestAfter = 10,
TransactionTrieRootDigestAfter = 11,
ReceiptTrieRootDigestAfter = 12,
2022-10-11 08:46:40 -07:00
/// The sizes of the `TrieEncodedChild` and `TrieEncodedChildLen` buffers. In other words, the
/// next available offset in these buffers.
TrieEncodedChildSize = 13,
2023-03-10 08:54:26 -08:00
// Block metadata.
BlockBeneficiary = 14,
BlockTimestamp = 15,
BlockNumber = 16,
BlockDifficulty = 17,
BlockGasLimit = 18,
BlockChainId = 19,
BlockBaseFee = 20,
2023-03-12 21:35:04 -07:00
/// Gas to refund at the end of the transaction.
RefundCounter = 21,
/// Length of the addresses access list.
AccessedAddressesLen = 22,
/// Length of the storage keys access list.
AccessedStorageKeysLen = 23,
2023-04-01 07:29:22 +02:00
/// Length of the self-destruct list.
SelfDestructListLen = 24,
/// Length of the bloom entry buffer.
BloomEntryLen = 25,
/// Length of the journal.
JournalLen = 26,
/// Length of the `JournalData` segment.
JournalDataLen = 27,
/// Current checkpoint.
CurrentCheckpoint = 28,
TouchedAddressesLen = 29,
// Gas cost for the access list in type-1 txns. See EIP-2930.
AccessListDataCost = 30,
// Start of the access list in the RLP for type-1 txns.
AccessListRlpStart = 31,
// Length of the access list in the RLP for type-1 txns.
AccessListRlpLen = 32,
// Boolean flag indicating if the txn is a contract creation txn.
ContractCreation = 33,
IsPrecompileFromEoa = 34,
2023-06-07 18:54:06 +02:00
CallStackDepth = 35,
/// Transaction logs list length
LogsLen = 36,
LogsDataLen = 37,
LogsPayloadLen = 38,
}
impl GlobalMetadata {
pub(crate) const COUNT: usize = 39;
pub(crate) fn all() -> [Self; Self::COUNT] {
[
Self::LargestContext,
Self::MemorySize,
Self::TrieDataSize,
2023-03-18 09:29:31 -07:00
Self::RlpDataSize,
Self::StateTrieRoot,
Self::TransactionTrieRoot,
Self::ReceiptTrieRoot,
2022-08-25 12:24:22 -07:00
Self::StateTrieRootDigestBefore,
2022-10-02 11:14:07 -07:00
Self::TransactionTrieRootDigestBefore,
Self::ReceiptTrieRootDigestBefore,
2022-08-25 12:24:22 -07:00
Self::StateTrieRootDigestAfter,
2022-10-02 11:14:07 -07:00
Self::TransactionTrieRootDigestAfter,
Self::ReceiptTrieRootDigestAfter,
2022-10-11 08:46:40 -07:00
Self::TrieEncodedChildSize,
2023-03-10 08:54:26 -08:00
Self::BlockBeneficiary,
Self::BlockTimestamp,
Self::BlockNumber,
Self::BlockDifficulty,
Self::BlockGasLimit,
Self::BlockChainId,
Self::BlockBaseFee,
2023-03-12 21:35:04 -07:00
Self::RefundCounter,
Self::AccessedAddressesLen,
Self::AccessedStorageKeysLen,
2023-04-01 07:29:22 +02:00
Self::SelfDestructListLen,
Self::BloomEntryLen,
Self::JournalLen,
Self::JournalDataLen,
Self::CurrentCheckpoint,
Self::TouchedAddressesLen,
Self::AccessListDataCost,
Self::AccessListRlpStart,
Self::AccessListRlpLen,
Self::ContractCreation,
Self::IsPrecompileFromEoa,
2023-06-07 18:54:06 +02:00
Self::CallStackDepth,
Self::LogsLen,
Self::LogsDataLen,
Self::LogsPayloadLen,
]
}
/// The variable name that gets passed into kernel assembly code.
pub(crate) fn var_name(&self) -> &'static str {
match self {
2023-03-10 08:54:26 -08:00
Self::LargestContext => "GLOBAL_METADATA_LARGEST_CONTEXT",
Self::MemorySize => "GLOBAL_METADATA_MEMORY_SIZE",
Self::TrieDataSize => "GLOBAL_METADATA_TRIE_DATA_SIZE",
2023-03-18 09:29:31 -07:00
Self::RlpDataSize => "GLOBAL_METADATA_RLP_DATA_SIZE",
2023-03-10 08:54:26 -08:00
Self::StateTrieRoot => "GLOBAL_METADATA_STATE_TRIE_ROOT",
Self::TransactionTrieRoot => "GLOBAL_METADATA_TXN_TRIE_ROOT",
Self::ReceiptTrieRoot => "GLOBAL_METADATA_RECEIPT_TRIE_ROOT",
Self::StateTrieRootDigestBefore => "GLOBAL_METADATA_STATE_TRIE_DIGEST_BEFORE",
Self::TransactionTrieRootDigestBefore => "GLOBAL_METADATA_TXN_TRIE_DIGEST_BEFORE",
Self::ReceiptTrieRootDigestBefore => "GLOBAL_METADATA_RECEIPT_TRIE_DIGEST_BEFORE",
Self::StateTrieRootDigestAfter => "GLOBAL_METADATA_STATE_TRIE_DIGEST_AFTER",
Self::TransactionTrieRootDigestAfter => "GLOBAL_METADATA_TXN_TRIE_DIGEST_AFTER",
Self::ReceiptTrieRootDigestAfter => "GLOBAL_METADATA_RECEIPT_TRIE_DIGEST_AFTER",
Self::TrieEncodedChildSize => "GLOBAL_METADATA_TRIE_ENCODED_CHILD_SIZE",
Self::BlockBeneficiary => "GLOBAL_METADATA_BLOCK_BENEFICIARY",
Self::BlockTimestamp => "GLOBAL_METADATA_BLOCK_TIMESTAMP",
Self::BlockNumber => "GLOBAL_METADATA_BLOCK_NUMBER",
Self::BlockDifficulty => "GLOBAL_METADATA_BLOCK_DIFFICULTY",
Self::BlockGasLimit => "GLOBAL_METADATA_BLOCK_GAS_LIMIT",
Self::BlockChainId => "GLOBAL_METADATA_BLOCK_CHAIN_ID",
Self::BlockBaseFee => "GLOBAL_METADATA_BLOCK_BASE_FEE",
2023-03-12 21:35:04 -07:00
Self::RefundCounter => "GLOBAL_METADATA_REFUND_COUNTER",
Self::AccessedAddressesLen => "GLOBAL_METADATA_ACCESSED_ADDRESSES_LEN",
Self::AccessedStorageKeysLen => "GLOBAL_METADATA_ACCESSED_STORAGE_KEYS_LEN",
2023-04-01 07:29:22 +02:00
Self::SelfDestructListLen => "GLOBAL_METADATA_SELFDESTRUCT_LIST_LEN",
Self::BloomEntryLen => "GLOBAL_METADATA_BLOOM_ENTRY_LEN",
Self::JournalLen => "GLOBAL_METADATA_JOURNAL_LEN",
Self::JournalDataLen => "GLOBAL_METADATA_JOURNAL_DATA_LEN",
Self::CurrentCheckpoint => "GLOBAL_METADATA_CURRENT_CHECKPOINT",
Self::TouchedAddressesLen => "GLOBAL_METADATA_TOUCHED_ADDRESSES_LEN",
Self::AccessListDataCost => "GLOBAL_METADATA_ACCESS_LIST_DATA_COST",
Self::AccessListRlpStart => "GLOBAL_METADATA_ACCESS_LIST_RLP_START",
Self::AccessListRlpLen => "GLOBAL_METADATA_ACCESS_LIST_RLP_LEN",
Self::ContractCreation => "GLOBAL_METADATA_CONTRACT_CREATION",
Self::IsPrecompileFromEoa => "GLOBAL_METADATA_IS_PRECOMPILE_FROM_EOA",
2023-06-07 18:54:06 +02:00
Self::CallStackDepth => "GLOBAL_METADATA_CALL_STACK_DEPTH",
Self::LogsLen => "GLOBAL_METADATA_LOGS_LEN",
Self::LogsDataLen => "GLOBAL_METADATA_LOGS_DATA_LEN",
Self::LogsPayloadLen => "GLOBAL_METADATA_LOGS_PAYLOAD_LEN",
}
}
}