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

log0

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

log1

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

log2

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

log3

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

log4

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