ethereum.forks.dao_fork.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
    value = get_storage(
44
        evm.message.block_env.state, evm.message.current_target, key
45
    )
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
    state = evm.message.block_env.state
69
    current_value = get_storage(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
80
    # OPERATION
81
    set_storage(state, evm.message.current_target, key, new_value)
82
83
    # PROGRAM COUNTER
84
    evm.pc += Uint(1)