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

log0

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

log1

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

log2

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

log3

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

log4

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