ethereum.byzantium.vm.instructions.storageethereum.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:
31 | """ |
---|---|
32 | Loads to the stack, the value corresponding to a certain key from the |
33 | storage of the current account. |
34 |
|
35 | Parameters |
36 | ---------- |
37 | evm : |
38 | The current EVM frame. |
39 |
|
40 | """ |
41 | # STACK |
42 | key = pop(evm.stack).to_be_bytes32() |
43 | |
44 | # GAS |
45 | charge_gas(evm, GAS_SLOAD) |
46 | |
47 | # OPERATION |
48 | value = get_storage( |
49 | evm.message.block_env.state, evm.message.current_target, key |
50 | ) |
51 | |
52 | push(evm.stack, value) |
53 | |
54 | # PROGRAM COUNTER |
55 | evm.pc += Uint(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:
59 | """ |
---|---|
60 | Stores a value at a certain key in the current context's storage. |
61 |
|
62 | Parameters |
63 | ---------- |
64 | evm : |
65 | The current EVM frame. |
66 |
|
67 | """ |
68 | # STACK |
69 | key = pop(evm.stack).to_be_bytes32() |
70 | new_value = pop(evm.stack) |
71 | |
72 | # GAS |
73 | state = evm.message.block_env.state |
74 | current_value = get_storage(state, evm.message.current_target, key) |
75 | if new_value != 0 and current_value == 0: |
76 | gas_cost = GAS_STORAGE_SET |
77 | else: |
78 | gas_cost = GAS_STORAGE_UPDATE |
79 | |
80 | if new_value == 0 and current_value != 0: |
81 | evm.refund_counter += int(GAS_STORAGE_CLEAR_REFUND) |
82 | |
83 | charge_gas(evm, gas_cost) |
84 | if evm.message.is_static: |
85 | raise WriteInStaticContext |
86 | set_storage(state, evm.message.current_target, key, new_value) |
87 | |
88 | # PROGRAM COUNTER |
89 | evm.pc += Uint(1) |