-
Notifications
You must be signed in to change notification settings - Fork 632
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07780b1
commit e047fb1
Showing
5 changed files
with
151 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
def tstore(computation): | ||
address = computation.msg.storage_address | ||
slot, value = computation.stack_pop_ints(2) | ||
|
||
computation.state.set_transient_storage(address, slot, value) | ||
|
||
|
||
def tload(computation): | ||
address = computation.msg.storage_address | ||
slot = computation.stack_pop1_int() | ||
state = computation.state | ||
value = state.get_transient_storage(address, slot) | ||
|
||
computation.push_int(value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from eth_utils import ( | ||
int_to_big_endian, | ||
) | ||
|
||
from eth.abc import ( | ||
TransientStorageAPI, | ||
) | ||
from eth.db.backends.memory import ( | ||
MemoryDB, | ||
) | ||
from eth.db.journal import ( | ||
JournalDB, | ||
) | ||
from eth.typing import ( | ||
Address, | ||
) | ||
from eth.validation import ( | ||
validate_canonical_address, | ||
validate_uint256, | ||
) | ||
|
||
|
||
class TransientStorage(TransientStorageAPI): | ||
def __init__(self): | ||
self._transient_storage = JournalDB(MemoryDB()) | ||
|
||
@staticmethod | ||
def _get_key(address: Address, slot: int) -> bytes: | ||
return address + int_to_big_endian(slot) | ||
|
||
def get_transient_storage(self, address: Address, slot: int) -> int: | ||
validate_canonical_address(address) | ||
validate_uint256(slot) | ||
|
||
key = self._get_key(address, slot) | ||
return self._transient_storage.get(key, 0) | ||
|
||
def set_transient_storage(self, address: Address, slot: int, value: int) -> None: | ||
validate_canonical_address(address) | ||
validate_uint256(slot) | ||
validate_uint256(value) | ||
|
||
key = self._get_key(address, slot) | ||
self._transient_storage[key] = value | ||
|
||
def record(self, checkpoint): | ||
self._transient_storage.record(checkpoint) | ||
|
||
def commit(self, checkpoint): | ||
self._transient_storage.commit(checkpoint) | ||
|
||
def discard(self, checkpoint): | ||
self._transient_storage.discard(checkpoint) |