From c5b120fe184507fd54a3601f4af58dd4de328e3b Mon Sep 17 00:00:00 2001 From: Joshua Colvin Date: Fri, 8 Dec 2023 13:48:24 -0700 Subject: [PATCH] add unsafe transient functions to storage --- stylus-sdk/src/storage/mod.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/stylus-sdk/src/storage/mod.rs b/stylus-sdk/src/storage/mod.rs index 80853ba8..af005ac4 100644 --- a/stylus-sdk/src/storage/mod.rs +++ b/stylus-sdk/src/storage/mod.rs @@ -82,6 +82,26 @@ pub unsafe fn store_bytes32(key: U256, data: B256) { unsafe { hostio::storage_store_bytes32(B256::from(key).as_ptr(), data.as_ptr()) }; } +/// Retrieves a 32-byte EVM word from transient storage directly, bypassing all caches. +/// +/// # Safety +/// +/// May alias storage. +pub unsafe fn transient_load_bytes32(key: U256) -> B256 { + let mut data = B256::ZERO; + unsafe { hostio::storage_transient_load_bytes32(B256::from(key).as_ptr(), data.as_mut_ptr()) }; + data +} + +/// Stores a 32-byte EVM word to transient storage directly, bypassing all caches. +/// +/// # Safety +/// +/// May alias storage. +pub unsafe fn transient_store_bytes32(key: U256, data: B256) { + unsafe { hostio::storage_transient_store_bytes32(B256::from(key).as_ptr(), data.as_ptr()) }; +} + /// Overwrites the value in a cell. #[inline] fn overwrite_cell(cell: &mut OnceCell, value: T) {