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