-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement transient get/set bytes32 hostios #92
base: testnet-2
Are you sure you want to change the base?
Changes from 11 commits
be5e5c8
e000029
d01b313
725abb9
bf46b3a
bdbdf68
298c531
a07656b
98d7bea
c5b120f
64c1e22
8f1e922
7f87b7c
910b386
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,24 @@ extern "C" { | |
/// [`SSTORE`]: https://www.evm.codes/#55 | ||
pub fn storage_store_bytes32(key: *const u8, value: *const u8); | ||
|
||
/// 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 transient storage at offset `key`, which will be `0` when not | ||
/// previously set. The semantics, then, are equivalent to that of the EVM's [`TLOAD`] opcode. | ||
/// | ||
/// [`TLOAD`]: https://www.evm.codes/#5c | ||
#[allow(dead_code)] | ||
pub fn storage_transient_load_bytes32(key: *const u8, dest: *mut u8); | ||
|
||
/// Stores a 32-byte value to permanent storage. Stylus's storage format is identical to that | ||
/// of the EVM. This means that, under the hood, this hostio is storing a 32-byte value into | ||
/// the EVM transient storage at offset `key`. Furthermore, refunds are tabulated exactly as in | ||
/// the EVM. The semantics, then, are equivalent to that of the EVM's [`TSTORE`] opcode. | ||
/// | ||
/// [`TSTORE`]: https://www.evm.codes/#5d | ||
#[allow(dead_code)] | ||
pub fn storage_transient_store_bytes32(key: *const u8, value: *const u8); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we discussed on slack, let's rename these There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
/// Gets the basefee of the current block. The semantics are equivalent to that of the EVM's | ||
/// [`BASEFEE`] opcode. | ||
/// | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
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<T>(cell: &mut OnceCell<T>, value: T) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's link the following for now since these opcodes don't yet exist
https://eips.ethereum.org/EIPS/eip-1153
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍