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