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:
24
    <snip>
34
    # STACK
35
    key = pop(evm.stack).to_be_bytes32()
36
37
    # GAS
38
    charge_gas(evm, GasCosts.SLOAD)
39
40
    # OPERATION
41
    tx_state = evm.message.tx_env.state
42
    value = get_storage(tx_state, evm.message.current_target, key)
43
44
    push(evm.stack, value)
45
46
    # PROGRAM COUNTER
47
    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:
51
    <snip>
60
    # STACK
61
    key = pop(evm.stack).to_be_bytes32()
62
    new_value = pop(evm.stack)
63
64
    # GAS
65
    tx_state = evm.message.tx_env.state
66
    current_value = get_storage(tx_state, evm.message.current_target, key)
67
    if new_value != 0 and current_value == 0:
68
        gas_cost = GasCosts.STORAGE_SET
69
    else:
70
        gas_cost = GasCosts.COLD_STORAGE_WRITE
71
72
    if new_value == 0 and current_value != 0:
73
        evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR
74
75
    charge_gas(evm, gas_cost)
76
    if evm.message.is_static:
77
        raise WriteInStaticContext
78
    set_storage(tx_state, evm.message.current_target, key, new_value)
79
80
    # PROGRAM COUNTER
81
    evm.pc += Uint(1)