ethereum.forks.tangerine_whistle.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:
30
    """
31
    Appends a log entry, having `num_topics` topics, to the evm logs.
32
33
    This will also expand the memory if the data (required by the log entry)
34
    corresponding to the memory is not accessible.
35
36
    Parameters
37
    ----------
38
    evm :
39
        The current EVM frame.
40
    num_topics :
41
        The number of topics to be included in the log entry.
42
43
    """
44
    # STACK
45
    memory_start_index = pop(evm.stack)
46
    size = pop(evm.stack)
47
48
    topics = []
49
    for _ in range(num_topics):
50
        topic = pop(evm.stack).to_be_bytes32()
51
        topics.append(topic)
52
53
    # GAS
54
    extend_memory = calculate_gas_extend_memory(
55
        evm.memory, [(memory_start_index, size)]
56
    )
57
    charge_gas(
58
        evm,
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
    # OPERATION
66
    evm.memory += b"\x00" * extend_memory.expand_by
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 = partial(log_n, num_topics=0)

log1

80
log1 = partial(log_n, num_topics=1)

log2

81
log2 = partial(log_n, num_topics=2)

log3

82
log3 = partial(log_n, num_topics=3)

log4

83
log4 = partial(log_n, num_topics=4)