You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `runCode` method is a helper for directly running EVM bytecode (e.g., for testing or utility purposes) without the full message/transaction context:
442
+
- Sets up a minimal message context for code execution
443
+
-**Directly calls `runInterpreter` to execute the provided bytecode**
444
+
- Does not go through the full message handling logic of `runCall`
445
+
446
+
The `runInterpreter` method is used by both `runCall` (via `_executeCall`/`_executeCreate`) and `runCode` to process the actual bytecode.
447
+
448
+
#### Bytecode Processing (Interpreter)
449
+
The Interpreter class is the core bytecode processor:
450
+
- Manages execution state (program counter, stack, memory, gas)
451
+
- Executes a loop that:
452
+
- Analyzes jump destinations
453
+
- Fetches the next opcode
454
+
- Calculates gas costs (static and dynamic)
455
+
- Executes the opcode handler
456
+
- Updates the program counter
457
+
- Emits step events for debugging/tracing
458
+
- Handles stack, memory, and storage operations
459
+
- Processes call and creation operations by delegating back to the EVM
460
+
461
+
#### Opcode Functions
462
+
Each opcode has an associated handler function that:
463
+
- Validates inputs
464
+
- Calculates dynamic gas costs
465
+
- Performs the opcode's logic (stack operations, memory operations, etc.)
466
+
- Updates the EVM state
467
+
- The program counter is incremented in between the execution of the gas handler and opcode logic handler functions, this should be considered e.g. if parsing immediate input parameters
468
+
- Special opcodes like `CALL`, `CREATE`, `DELEGATECALL` create a new message and call back to the EVM's `runCall` method
469
+
470
+
#### Journal and State Management
471
+
- State changes are tracked in a journal system
472
+
- The journal supports checkpointing and reversion
473
+
- Transient storage (EIP-1153) has its own checkpoint mechanism
474
+
- When a message completes successfully, changes are committed to the state
475
+
- On failure (exceptions), changes are reverted
476
+
477
+
This layered architecture provides separation of concerns while allowing for the complex interactions needed to execute smart contracts on the Ethereum platform.
0 commit comments