ethereum.forks.amsterdam.vm.instructions.log

Ethereum Virtual Machine (EVM) Logging Instructions.

.. contents:: Table of Contents :backlinks: none :local:

Introduction

Implementations of the EVM logging instructions.

log_n

Appends a log entry, having num_topics topics, to the evm logs.

This will also expand the memory if the data (required by the log entry) corresponding to the memory is not accessible.

Parameters

evm : The current EVM frame. num_topics : The number of topics to be included in the log entry.

def log_n(evm: Evm, ​​num_topics: int) -> None:
33
    <snip>
47
    # STACK
48
    memory_start_index = pop(evm.stack)
49
    size = pop(evm.stack)
50
51
    topics = []
52
    for _ in range(num_topics):
53
        topic = pop(evm.stack).to_be_bytes32()
54
        topics.append(topic)
55
56
    # GAS
57
    extend_memory = calculate_gas_extend_memory(
58
        evm.memory, [(memory_start_index, size)]
59
    )
60
    charge_gas(
61
        evm,
62
        ExecutionGas(
63
            GasCosts.OPCODE_LOG_BASE
64
            + GasCosts.OPCODE_LOG_DATA_PER_BYTE * Uint(size)
65
            + GasCosts.OPCODE_LOG_TOPIC * Uint(num_topics)
66
            + extend_memory.cost
67
        ),
68
    )
69
70
    # OPERATION
71
    evm.memory += b"\x00" * extend_memory.expand_by
72
    if evm.is_static:
73
        raise WriteInStaticContext
74
    log_entry = Log(
75
        address=evm.current_target,
76
        topics=tuple(topics),
77
        data=memory_read_bytes(evm.memory, memory_start_index, size),
78
    )
79
80
    evm.logs = evm.logs + (log_entry,)
81
82
    # PROGRAM COUNTER
83
    evm.pc += Uint(1)

log0

86
log0: Callable[[Evm], None] = partial(log_n, num_topics=0)

log1

87
log1: Callable[[Evm], None] = partial(log_n, num_topics=1)

log2

88
log2: Callable[[Evm], None] = partial(log_n, num_topics=2)

log3

89
log3: Callable[[Evm], None] = partial(log_n, num_topics=3)

log4

90
log4: Callable[[Evm], None] = partial(log_n, num_topics=4)