Ethereum Virtual Machine (EVM) Logging Instructions
Table of Contents
Introduction
Implementations of the EVM logging instructions.
Module Contents
Functions
Appends a log entry, having num_topics topics, to the evm logs. |
Attributes
Module Details
log_n
- log_n(evm: ethereum.berlin.vm.Evm, num_topics: ethereum.base_types.U256) → None
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: U256) -> None:
# STACK
memory_start_index = pop(evm.stack)
size = pop(evm.stack)
topics = []
for _ in range(num_topics):
topic = pop(evm.stack).to_be_bytes32()
topics.append(topic)
# GAS
extend_memory = calculate_gas_extend_memory(
evm.memory, [(memory_start_index, size)]
)
charge_gas(
evm,
GAS_LOG
+ GAS_LOG_DATA * size
+ GAS_LOG_TOPIC * num_topics
+ extend_memory.cost,
)
# OPERATION
evm.memory += b"\x00" * extend_memory.expand_by
ensure(not evm.message.is_static, WriteInStaticContext)
log_entry = Log(
address=evm.message.current_target,
topics=tuple(topics),
data=memory_read_bytes(evm.memory, memory_start_index, size),
)
evm.logs = evm.logs + (log_entry,)
# PROGRAM COUNTER
evm.pc += 1
log0
- log0
log0 = partial(log_n, num_topics=0)
log1
- log1
log1 = partial(log_n, num_topics=1)
log2
- log2
log2 = partial(log_n, num_topics=2)
log3
- log3
log3 = partial(log_n, num_topics=3)
log4
- log4
log4 = partial(log_n, num_topics=4)