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
    tx_state = evm.message.tx_env.state
45
    value = get_storage(tx_state, evm.message.current_target, key)
46
47
    push(evm.stack, value)
48
49
    # PROGRAM COUNTER
50
    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:
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
    tx_state = evm.message.tx_env.state
69
    current_value = get_storage(tx_state, evm.message.current_target, key)
70
    if new_value != 0 and current_value == 0:
71
        gas_cost = GasCosts.STORAGE_SET
72
    else:
73
        gas_cost = GasCosts.COLD_STORAGE_WRITE
74
75
    if new_value == 0 and current_value != 0:
76
        evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR
77
78
    charge_gas(evm, gas_cost)
79
    if evm.message.is_static:
80
        raise WriteInStaticContext
81
    set_storage(tx_state, evm.message.current_target, key, new_value)
82
83
    # PROGRAM COUNTER
84
    evm.pc += Uint(1)