Skip to content
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

Add transient hostios #15

Open
wants to merge 4 commits into
base: testnet-2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions include/hostio.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ VM_HOOK(account_codehash) void account_codehash(const uint8_t * address, uint8_t
* 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.
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's re-add these, since they're the way the blocks are currently formatted

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

*
* [`SLOAD`]: https://www.evm.codes/#54
*/
VM_HOOK(storage_load_bytes32) void storage_load_bytes32(const uint8_t * key, uint8_t * dest);
Expand All @@ -46,11 +46,31 @@ VM_HOOK(storage_load_bytes32) void storage_load_bytes32(const uint8_t * key, uin
* of the EVM. This means that, under the hood, this hostio is storing a 32-byte value into
* the EVM state trie at offset `key`. Furthermore, refunds are tabulated exactly as in the
* EVM. The semantics, then, are equivalent to that of the EVM's [`SSTORE`] opcode.
*
*
* [`SSTORE`]: https://www.evm.codes/#55
*/
VM_HOOK(storage_store_bytes32) void storage_store_bytes32(const uint8_t * key, const uint8_t * value);

/**
* Reads a 32-byte value from transient 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
*/
VM_HOOK(transient_load_bytes32) void transient_load_bytes32(const uint8_t * key, uint8_t * dest);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed on slack, let's rename these.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


/**
* 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
Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

*/
VM_HOOK(transient_store_bytes32) void transient_store_bytes32(const uint8_t * key, const uint8_t * value);

/**
* Gets the basefee of the current block. The semantics are equivalent to that of the EVM's
* [`BASEFEE`] opcode.
Expand Down
23 changes: 22 additions & 1 deletion include/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extern "C" {

/**
* storage_load / store load or store a value from storage accordingly.
*
*
* The value of the first "storage" pointer is not used.
* generated headers provide:
* a const storage pointer when working for a view-only function
Expand All @@ -42,6 +42,27 @@ inline void storage_store(void *storage, const uint8_t *key, const uint8_t *valu
storage_store_bytes32(key, value);
}

/**
* transient_load / store load or store a value from transient storage accordingly.
*
* The value of the first "storage" pointer is not used.
* generated headers provide:
* a const storage pointer when working for a view-only function
* a non const pointer for a mutating function
* no pointer (so don't call transient_load) for a pure function
*
*/
inline void transient_load(const void* storage, const uint8_t *key, uint8_t *dest) {
transient_load_bytes32(key, dest);
}

/**
* see documentation for transient_load
*/
inline void transient_store(void *storage, const uint8_t *key, const uint8_t *value) {
transient_store_bytes32(key, value);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's drop these for now, since we're not yet supporting higher-order affordances

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

/**
* calculate slot for a map with base slot "storage" to put "key"
* If key requires padding it must be applied before calling this function
Expand Down