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