ethereum.spurious_dragon.vm.instructions.storageethereum.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:
31
    """
32
    Loads to the stack, the value corresponding to a certain key from the
33
    storage of the current account.
34
35
    Parameters
36
    ----------
37
    evm :
38
        The current EVM frame.
39
40
    """
41
    # STACK
42
    key = pop(evm.stack).to_be_bytes32()
43
44
    # GAS
45
    charge_gas(evm, GAS_SLOAD)
46
47
    # OPERATION
48
    value = get_storage(evm.env.state, evm.message.current_target, key)
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
    current_value = get_storage(evm.env.state, evm.message.current_target, key)
72
    if new_value != 0 and current_value == 0:
73
        gas_cost = GAS_STORAGE_SET
74
    else:
75
        gas_cost = GAS_STORAGE_UPDATE
76
77
    if new_value == 0 and current_value != 0:
78
        evm.refund_counter += int(GAS_STORAGE_CLEAR_REFUND)
79
80
    charge_gas(evm, gas_cost)
80
81
    # OPERATION
81
    if evm.message.is_static:
82
        raise WriteInStaticContext
83
    set_storage(evm.env.state, evm.message.current_target, key, new_value)
84
85
    # PROGRAM COUNTER
86
    evm.pc += Uint(1)