ethereum.homestead.vm.instructions.storageethereum.dao_fork.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( |
48 | evm.message.block_env.state, evm.message.current_target, key |
49 | ) |
50 | |
51 | push(evm.stack, value) |
52 | |
53 | # PROGRAM COUNTER |
54 | 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:
58 | """ |
---|---|
59 | Stores a value at a certain key in the current context's storage. |
60 |
|
61 | Parameters |
62 | ---------- |
63 | evm : |
64 | The current EVM frame. |
65 |
|
66 | """ |
67 | # STACK |
68 | key = pop(evm.stack).to_be_bytes32() |
69 | new_value = pop(evm.stack) |
70 | |
71 | # GAS |
72 | state = evm.message.block_env.state |
73 | current_value = get_storage(state, evm.message.current_target, key) |
74 | if new_value != 0 and current_value == 0: |
75 | gas_cost = GAS_STORAGE_SET |
76 | else: |
77 | gas_cost = GAS_STORAGE_UPDATE |
78 | |
79 | if new_value == 0 and current_value != 0: |
80 | evm.refund_counter += int(GAS_STORAGE_CLEAR_REFUND) |
81 | |
82 | charge_gas(evm, gas_cost) |
83 | |
84 | # OPERATION |
85 | set_storage(state, evm.message.current_target, key, new_value) |
86 | |
87 | # PROGRAM COUNTER |
88 | evm.pc += Uint(1) |