ethereum.constantinople.vm.instructions.storage
Ethereum Virtual Machine (EVM) Storage Instructions ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. contents:: Table of Contents :backlinks: none :local:
Introduction
Implementations of the EVM storage related instructions.
sload
Loads to the stack, the value corresponding to a certain key from the storage of the current account.
Parameters
evm : The current EVM frame.
def sload(evm: Evm) -> None:
29 | """ |
---|---|
30 | Loads to the stack, the value corresponding to a certain key from the |
31 | storage of the current account. |
32 |
|
33 | Parameters |
34 | ---------- |
35 | evm : |
36 | The current EVM frame. |
37 |
|
38 | """ |
39 | # STACK |
40 | key = pop(evm.stack).to_be_bytes32() |
41 | |
42 | # GAS |
43 | charge_gas(evm, GAS_SLOAD) |
44 | |
45 | # OPERATION |
46 | value = get_storage(evm.env.state, evm.message.current_target, key) |
47 | |
48 | push(evm.stack, value) |
49 | |
50 | # PROGRAM COUNTER |
51 | evm.pc += 1 |
sstore
Stores a value at a certain key in the current context's storage.
Parameters
evm : The current EVM frame.
def sstore(evm: Evm) -> None:
55 | """ |
---|---|
56 | Stores a value at a certain key in the current context's storage. |
57 |
|
58 | Parameters |
59 | ---------- |
60 | evm : |
61 | The current EVM frame. |
62 |
|
63 | """ |
64 | # STACK |
65 | key = pop(evm.stack).to_be_bytes32() |
66 | new_value = pop(evm.stack) |
67 | |
68 | # GAS |
69 | current_value = get_storage(evm.env.state, evm.message.current_target, key) |
70 | if new_value != 0 and current_value == 0: |
71 | gas_cost = GAS_STORAGE_SET |
72 | else: |
73 | gas_cost = GAS_STORAGE_UPDATE |
74 | |
75 | if new_value == 0 and current_value != 0: |
76 | evm.refund_counter += GAS_STORAGE_CLEAR_REFUND |
77 | |
78 | charge_gas(evm, gas_cost) |
79 | if evm.message.is_static: |
80 | raise WriteInStaticContext |
81 | set_storage(evm.env.state, evm.message.current_target, key, new_value) |
82 | |
83 | # PROGRAM COUNTER |
84 | evm.pc += 1 |