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

log0

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

log1

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

log2

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

log3

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

log4

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