ethereum.forks.frontier.vm.instructions.logethereum.forks.homestead.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 | """ |
|---|---|
| 33 | Appends a log entry, having `num_topics` topics, to the evm logs. |
| 34 | |
| 35 | This will also expand the memory if the data (required by the log entry) |
| 36 | corresponding to the memory is not accessible. |
| 37 | |
| 38 | Parameters |
| 39 | ---------- |
| 40 | evm : |
| 41 | The current EVM frame. |
| 42 | num_topics : |
| 43 | The number of topics to be included in the log entry. |
| 44 | |
| 45 | """ |
| 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 | GAS_LOG |
| 62 | + GAS_LOG_DATA * Uint(size) |
| 63 | + GAS_LOG_TOPIC * Uint(num_topics) |
| 64 | + extend_memory.cost, |
| 65 | ) |
| 66 | |
| 67 | # OPERATION |
| 68 | evm.memory += b"\x00" * extend_memory.expand_by |
| 69 | log_entry = Log( |
| 70 | address=evm.message.current_target, |
| 71 | topics=tuple(topics), |
| 72 | data=memory_read_bytes(evm.memory, memory_start_index, size), |
| 73 | ) |
| 74 | |
| 75 | evm.logs = evm.logs + (log_entry,) |
| 76 | |
| 77 | # PROGRAM COUNTER |
| 78 | evm.pc += Uint(1) |
log0
| 81 | log0 = partial(log_n, num_topics=0) |
|---|
log1
| 82 | log1 = partial(log_n, num_topics=1) |
|---|
log2
| 83 | log2 = partial(log_n, num_topics=2) |
|---|
log3
| 84 | log3 = partial(log_n, num_topics=3) |
|---|
log4
| 85 | log4 = partial(log_n, num_topics=4) |
|---|