ethereum.forks.muir_glacier.vm.instructions.logethereum.forks.berlin.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:
| 33 | """ |
|---|---|
| 34 | Appends a log entry, having `num_topics` topics, to the evm logs. |
| 35 | |
| 36 | This will also expand the memory if the data (required by the log entry) |
| 37 | corresponding to the memory is not accessible. |
| 38 | |
| 39 | Parameters |
| 40 | ---------- |
| 41 | evm : |
| 42 | The current EVM frame. |
| 43 | num_topics : |
| 44 | The number of topics to be included in the log entry. |
| 45 | |
| 46 | """ |
| 47 | # STACK |
| 48 | memory_start_index = pop(evm.stack) |
| 49 | size = pop(evm.stack) |
| 50 | |
| 51 | topics = [] |
| 52 | for _ in range(num_topics): |
| 53 | topic = pop(evm.stack).to_be_bytes32() |
| 54 | topics.append(topic) |
| 55 | |
| 56 | # GAS |
| 57 | extend_memory = calculate_gas_extend_memory( |
| 58 | evm.memory, [(memory_start_index, size)] |
| 59 | ) |
| 60 | charge_gas( |
| 61 | evm, |
| 62 | GAS_LOG |
| 63 | + GAS_LOG_DATA * Uint(size) |
| 64 | + GAS_LOG_TOPIC * Uint(num_topics) |
| 65 | + extend_memory.cost, |
| 66 | ) |
| 67 | |
| 68 | # OPERATION |
| 69 | evm.memory += b"\x00" * extend_memory.expand_by |
| 70 | if evm.message.is_static: |
| 71 | raise WriteInStaticContext |
| 72 | log_entry = Log( |
| 73 | address=evm.message.current_target, |
| 74 | topics=tuple(topics), |
| 75 | data=memory_read_bytes(evm.memory, memory_start_index, size), |
| 76 | ) |
| 77 | |
| 78 | evm.logs = evm.logs + (log_entry,) |
| 79 | |
| 80 | # PROGRAM COUNTER |
| 81 | evm.pc += Uint(1) |
log0
| 84 | log0 = partial(log_n, num_topics=0) |
|---|
log1
| 85 | log1 = partial(log_n, num_topics=1) |
|---|
log2
| 86 | log2 = partial(log_n, num_topics=2) |
|---|
log3
| 87 | log3 = partial(log_n, num_topics=3) |
|---|
log4
| 88 | log4 = partial(log_n, num_topics=4) |
|---|