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