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:
23
    <snip>
33
    # STACK
34
    key = pop(evm.stack).to_be_bytes32()
35
36
    # GAS
37
    charge_gas(evm, GasCosts.SLOAD)
38
39
    # OPERATION
40
    tx_state = evm.message.tx_env.state
41
    value = get_storage(tx_state, evm.message.current_target, key)
42
43
    push(evm.stack, value)
44
45
    # PROGRAM COUNTER
46
    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:
50
    <snip>
59
    # STACK
60
    key = pop(evm.stack).to_be_bytes32()
61
    new_value = pop(evm.stack)
62
63
    # GAS
64
    tx_state = evm.message.tx_env.state
65
    current_value = get_storage(tx_state, evm.message.current_target, key)
66
    if new_value != 0 and current_value == 0:
67
        gas_cost = GasCosts.STORAGE_SET
68
    else:
69
        gas_cost = GasCosts.COLD_STORAGE_WRITE
70
71
    if new_value == 0 and current_value != 0:
72
        evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR
73
74
    charge_gas(evm, gas_cost)
75
76
    # OPERATION
77
    set_storage(tx_state, evm.message.current_target, key, new_value)
78
79
    # PROGRAM COUNTER
80
    evm.pc += Uint(1)