Skip to content

Add LOG0–LOG4 event logging opcodes#19

Open
mw2000 wants to merge 1 commit intomainfrom
feat/log-opcodes
Open

Add LOG0–LOG4 event logging opcodes#19
mw2000 wants to merge 1 commit intomainfrom
feat/log-opcodes

Conversation

@mw2000
Copy link
Owner

@mw2000 mw2000 commented Mar 5, 2026

Summary

  • Implement LOG0–LOG4 opcodes (0xA0–0xA4) for EVM event emission
  • Add logs field to MachineState to accumulate log entries
  • Add EEVM.logs/1 accessor to public API

Changes

  • machine_state.ex: Added logs: [] field for log accumulation
  • opcodes.ex: Added LOG0–LOG4 opcode definitions with correct input counts (2+N topics)
  • gas.ex: Added log gas constants (Glog=375, Glogtopic=375, Glogdata=8) and log_cost/2 helper
  • executor.ex: Implemented 5 execute_opcode clauses — pops offset/size/topics, charges dynamic gas, reads memory, creates log entry with contract address
  • eevm.ex: Added logs/1 public accessor

Gas Formula

375 + 375 * topic_count + 8 * data_byte_size + memory expansion cost

Tests

10 new tests covering LOG0–LOG4 with topics, data, gas calculation, memory expansion, accumulation, and contract address correctness.

Closes #9

@mw2000 mw2000 force-pushed the feat/log-opcodes branch from 5612247 to bc49858 Compare March 5, 2026 22:18
@mw2000 mw2000 force-pushed the feat/log-opcodes branch from bc49858 to 0de6121 Compare March 5, 2026 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement LOG0–LOG4 opcodes

1 participant