Ethereum Virtual Machine (EVM) Storage Instructions

Introduction

Implementations of the EVM storage related instructions.

Module Contents

Functions

sload

Loads to the stack, the value corresponding to a certain key from the

sstore

Stores a value at a certain key in the current context’s storage.

Module Details

sload

sload(evm: ethereum.frontier.vm.Evm)None

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:
    # STACK
    key = pop(evm.stack).to_be_bytes32()

    # GAS
    charge_gas(evm, GAS_SLOAD)

    # OPERATION
    value = get_storage(evm.env.state, evm.message.current_target, key)

    push(evm.stack, value)

    # PROGRAM COUNTER
    evm.pc += 1

sstore

sstore(evm: ethereum.frontier.vm.Evm)None

Stores a value at a certain key in the current context’s storage.

Parameters

evm – The current EVM frame.

def sstore(evm: Evm) -> None:
    # STACK
    key = pop(evm.stack).to_be_bytes32()
    new_value = pop(evm.stack)

    # GAS
    current_value = get_storage(evm.env.state, evm.message.current_target, key)
    if new_value != 0 and current_value == 0:
        gas_cost = GAS_STORAGE_SET
    else:
        gas_cost = GAS_STORAGE_UPDATE

    charge_gas(evm, gas_cost)

    if new_value == 0 and current_value != 0:
        evm.refund_counter += GAS_STORAGE_CLEAR_REFUND

    # OPERATION
    set_storage(evm.env.state, evm.message.current_target, key, new_value)

    # PROGRAM COUNTER
    evm.pc += 1