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