pub trait StorageAccess {
// Required methods
fn storage_load_bytes32(&self, key: U256) -> B256;
unsafe fn storage_cache_bytes32(&self, key: U256, value: B256);
fn flush_cache(&self, clear: bool);
}Expand description
Provides access to storage access and mutation via host methods.
Required Methods§
Sourcefn storage_load_bytes32(&self, key: U256) -> B256
fn storage_load_bytes32(&self, key: U256) -> B256
Reads a 32-byte value from permanent storage. Stylus’s storage format is identical to
that of the EVM. This means that, under the hood, this hostio is accessing the 32-byte
value stored in the EVM state trie at offset key, which will be 0 when not previously
set. The semantics, then, are equivalent to that of the EVM’s SLOAD opcode.
Note: the Stylus VM implements storage caching. This means that repeated calls to the same key will cost less than in the EVM.
Sourceunsafe fn storage_cache_bytes32(&self, key: U256, value: B256)
unsafe fn storage_cache_bytes32(&self, key: U256, value: B256)
Writes a 32-byte value to the permanent storage cache. Stylus’s storage format is identical to that
of the EVM. This means that, under the hood, this hostio represents storing a 32-byte value into
the EVM state trie at offset key. Refunds are tabulated exactly as in the EVM. The semantics, then,
are equivalent to that of the EVM’s SSTORE opcode.
Note: because the value is cached, one must call flush_cache to persist it.
§Safety
May alias storage.
Sourcefn flush_cache(&self, clear: bool)
fn flush_cache(&self, clear: bool)
Persists any dirty values in the storage cache to the EVM state trie, dropping the cache entirely if requested.
Analogous to repeated invocations of SSTORE.