8000 πŸ—οΈ refactor: reorganize EVM files into logical folders and prepare import fixes by roninjin10 Β· Pull Request #1801 Β· evmts/tevm-monorepo Β· GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

πŸ—οΈ refactor: reorganize EVM files into logical folders and prepare import fixes #1801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 0 commits into from

Conversation

roninjin10
Copy link
Collaborator
@roninjin10 roninjin10 commented Jun 8, 2025

Description

This PR reorganizes the EVM codebase into a more structured directory layout, grouping related files into logical modules. Key changes include:

  • Added "Project Status" section to CLAUDE.md clarifying this is a greenfield project with no backward compatibility requirements
  • Added documentation for "Eager Operation Array Analysis" optimization strategy in CLAUDE.md
  • Restructured directories to group related components:
    • /access_list for access list related files
    • /constants for EVM constants
    • /contract for contract-related code
    • /execution for opcode implementations (renamed from /opcodes)
    • /hardforks for hardfork specifications
    • /jump_table for opcode mapping
    • /opcodes for opcode definitions
    • /stack for stack implementation
    • /state for EVM state management
  • Simplified error mapping module to focus on core functionality
  • Renamed RunResult to InterpretResult for clarity
  • Updated import paths throughout the codebase to reflect the new structure

Testing

All existing tests continue to pass with the new directory structure. The code changes are purely organizational and don't modify any functional behavior.

Additional Information

Your ENS/address:

Summary by CodeRabbit

  • New Features
    • Expanded documentation with new sections on project status and future optimization strategies for improved performance.
  • Bug Fixes
    • Enhanced error handling with new error types for stack and memory issues.
  • Refactor
    • Standardized and clarified error naming conventions for stack operations.
    • Updated function signatures and types for improved clarity and consistency.
    • Reorganized file structure and import paths for better maintainability.
  • Chores
    • Improved and expanded documentation throughout the codebase.
    • Added or updated TODO comments for unused code and future tasks.

Copy link
vercel bot commented Jun 8, 2025

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Updated (UTC)
node βœ… Ready (Inspect) Visit Preview Jun 8, 2025 6:56am
tevm-monorepo-app βœ… Ready (Inspect) Visit Preview Jun 8, 2025 6:56am
1 Skipped Deployment
Name Status Preview Updated (UTC)
tevm-monorepo-tevm ⬜️ Ignored (Inspect) Jun 8, 2025 6:56am

@vercel vercel bot temporarily deployed to Preview – node June 8, 2025 06:14 Inactive
Copy link
changeset-bot bot commented Jun 8, 2025

⚠️ No Changeset found

Latest commit: 86c4017

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor 8000
coderabbitai bot commented Jun 8, 2025

Walkthrough

This set of changes reorganizes the EVM codebase by updating import paths to reflect a new directory structure, renames stack error variants for clarity, refactors error mapping to use direct try/catch patterns, and updates function signatures to use new types. Documentation is enhanced throughout, with new sections and detailed comments added, and some obsolete files are removed or marked as unused.

Changes

Files/Groups Change Summary
src/evm/execution/*.zig, src/evm/contract/*.zig, src/evm/stack/*.zig, src/evm/jump_table/*.zig, src/evm/opcodes/*.zig, src/evm/frame.zig, src/evm/state/state.zig, src/evm/hardforks/chain_rules.zig, src/evm/interpret_result.zig Updated import paths to reflect new directory structure; no logic changes.
src/evm/stack/stack.zig Renamed stack error variants to explicit names (e.g., Overflow β†’ StackOverflow); updated references throughout.
src/evm/execution/execution_error.zig Added new error variants: MemoryLimitExceeded, StackOutOfBounds, StackInvalidPosition; updated description function.
src/evm/error_mapping.zig Refactored error mapping: removed mapping functions, replaced with inline try/catch and direct error translation; updated storage function signatures to use concrete Address type.
src/evm/vm.zig Changed depth type to u32; updated main interpret function signatures to use InterpretResult instead of RunResult; simplified some control flow.
src/evm/opcodes/opcode.zig Inlined MemorySize struct definition, replacing import; minor whitespace cleanup.
src/evm/memory_size.zig Deleted file; removed MemorySize struct and related documentation.
src/evm/CLAUDE.md Enhanced documentation: added "Project Status" and "Eager Operation Array Analysis" sections; minor whitespace cleanup.
src/evm/execution/environment.zig Removed explanatory comments; replaced error-mapped memory copy with direct method calls.
src/evm/contract/bitvec.zig, src/evm/contract/contract.zig Changed import paths for constants, execution_error, and log modules.
src/evm/execution/package.zig Updated re-exported module import paths to new structure.
src/evm/fee_market.zig, src/evm/wasm_stubs.zig Added TODO comments; reformatted methods in WASM stubs for clarity.
src/evm/contract/eip_7702_bytecode.zig Added detailed documentation comments and TODOs; no logic changes.
src/evm/context.zig Removed trailing whitespace in doc comments.
build.zig, Cargo.toml, src/compilers/rust_build.zig Standardized directory and import paths to lowercase; updated workspace and build script paths accordingly.
Various src/*/*.zig and test/*/*.zig files Updated import paths to use "tevm/" prefix and lowercase directory names; no logic changes.
src/evm/stack/validation_patterns.zig, src/evm/stack/stack_validation.zig Updated import paths to new directory structure.

Sequence Diagram(s)

sequenceDiagram
    participant VM
    participant Stack
    participant Memory
    participant Storage

    Note over VM: Main interpret loop (simplified)
    VM->>Stack: stack_pop()/stack_push()
    Note right of Stack: Returns or throws Stack* errors
    VM->>Memory: memory_set_data(), memory_get_slice()
    Note right of Memory: Returns or throws Memory* errors
    VM->>Storage: vm_get_storage()/vm_set_storage()
    Note right of Storage: Returns or throws OutOfMemory
    Note over VM: Errors are caught and mapped inline
Loading

Possibly related PRs

  • evmts/tevm-monorepo#1754: Adds the initial eip_7702_bytecode.zig module, which is further documented and clarified in this PR.
  • evmts/tevm-monorepo#1752: Refactors the Vm.zig file by changing struct visibility and adding a field, related to VM code changes alongside this PR's import and documentation updates.
  • evmts/tevm-monorepo#1759: Renames and reorganizes source files and import paths to snake_case, reflecting the same structural refactoring effort as this PR.

Poem

In burrows deep, I hop with glee,
For imports now are clear to see!
Stack errors wear their names with pride,
And docs abound, well-specified.
The memory’s sized, the code refinesβ€”
This garden’s neat, with tidy lines!
(A bunny’s work, well done, aligns.) πŸ‡βœ¨


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share
πŸͺ§ Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

πŸ”­ Outside diff range comments (5)
src/evm/execution/storage.zig (2)

50-55: πŸ› οΈ Refactor suggestion

Hoist Contract import out of function scope
Importing Contract inside the if (vm.chain_rules.IsBerlin) block duplicates the import and adds unnecessary overhead. Move const Contract = @import("../contract/contract.zig"); to the file-level imports above.

Proposed diff:

--- a/src/evm/execution/storage.zig
+++ b/src/evm/execution/storage.zig
@@
 const error_mapping = @import("../error_mapping.zig");
+const Contract = @import("../contract/contract.zig");

 /// EIP-3529 (London) gas costs for SSTORE
 const SSTORE_SET_GAS: u64 = 20000;
@@ pub fn op_sload(...){
-        const Contract = @import("../contract/contract.zig");
+        // use top-level Contract import

92-97: πŸ› οΈ Refactor suggestion

Hoist and consolidate Contract import in op_sstore
The same Contract import is repeated inside op_sstore. Move it to the top-level imports and remove this in-function import to DRY up the code.

Proposed diff:

--- a/src/evm/execution/storage.zig
+++ b/src/evm/execution/storage.zig
@@ pub fn op_sstore(...){
-    const Contract = @import("../contract/contract.zig");
+    // use top-level Contract import
src/evm/evm.zig (1)

65-191: πŸ’‘ Verification agent

🧩 Analysis chain

Verify the new directory structure and import paths.

The reorganization into logical folders looks excellent for maintainability. However, please ensure all import paths reference existing files in the new structure.


🏁 Script executed:

#!/bin/bash
# Description: Verify that all import paths in evm.zig reference existing files
# Expected: All imports should resolve to valid files

# Check each import path exists
declare -a imports=(
    "src/evm/contract/code_analysis.zig"
    "src/evm/contract/contract.zig"
    "src/evm/execution/execution_error.zig"
    "src/evm/hardforks/hardfork.zig"
    "src/evm/jump_table/jump_table.zig"
    "src/evm/opcodes/opcode.zig"
    "src/evm/opcodes/operation.zig"
    "src/evm/stack/stack.zig"
    "src/evm/stack/stack_validation.zig"
    "src/evm/contract/storage_pool.zig"
    "src/evm/execution/package.zig"
    "src/evm/contract/bitvec.zig"
    "src/evm/hardforks/chain_rules.zig"
    "src/evm/constants/constants.zig"
    "src/evm/contract/eip_7702_bytecode.zig"
    "src/evm/constants/gas_constants.zig"
    "src/evm/constants/memory_limits.zig"
    "src/evm/interpret_result.zig"
    "src/evm/access_list/access_list.zig"
)

echo "Checking import paths exist..."
for import in "${imports[@]}"; do
    if [[ -f "$import" ]]; then
        echo "βœ“ $import"
    else
        echo "βœ— MISSING: $import"
    fi
done

# Also check that InterpretResult type exists and RunResult doesn't
echo -e "\nChecking type definitions..."
if fd interpret_result.zig --exec rg -q "InterpretResult"; then
    echo "βœ“ InterpretResult type found"
else
    echo "βœ— InterpretResult type not found"
fi

Length of output: 3880


🏁 Script executed:

#!/bin/bash
# Inspect definitions in src/evm/interpret_result.zig

FILE="src/evm/interpret_result.zig"
if [[ -f "$FILE" ]]; then
  echo "=== $FILE ==="
  sed -n '1,200p' "$FILE"
  echo -e "\nSearching for 'pub const' definitions:"
  rg -n "pub const" "$FILE"
else
  echo "βœ— File not found: $FILE"
fi

Length of output: 3675


Import Paths Validated – Update InterpretResult Docs

All reorganized import paths in src/evm/evm.zig resolve successfully. One remaining change is needed in the newly renamed interpret_result.zig:

β€’ In src/evm/interpret_result.zig, the top‐level documentation still refers to β€œRunResult” even though the module (and its alias in evm.zig) is now InterpretResult. Please update these comments for consistency:

 /// Result of an EVM execution run.
-///
-/// RunResult encapsulates the outcome of executing EVM bytecode, including
+///
+/// InterpretResult encapsulates the outcome of executing EVM bytecode, including
src/evm/contract/eip_7702_bytecode.zig (2)

76-82: πŸ› οΈ Refactor suggestion

Add input validation to prevent potential issues.

The new_raw function doesn't validate the magic bytes or minimum length, which could lead to malformed instances.

 pub fn new_raw(bytes: []const u8) !Self {
+    if (bytes.len < 22) {
+        return error.InvalidBytecodeLength;
+    }
+    if (!std.mem.eql(u8, bytes[0..2], &EIP7702_MAGIC_BYTES)) {
+        return error.InvalidMagicBytes;
+    }
     var address: Address.Address = undefined;
-    if (bytes.len > 20) {
-        @memcpy(&address, bytes[2..22]);
-    }
+    @memcpy(&address, bytes[2..22]);
     return Self.new(address);
 }

99-102: ⚠️ Potential issue

Complete the raw function implementation.

The function returns an empty slice instead of the 10000 proper 22-byte bytecode format. This breaks the contract of the function.

 pub fn raw(self: *const Self) []const u8 {
-    _ = self;
-    return &[_]u8{};
+    // TODO: This should return a properly allocated 22-byte array
+    // For now, this is a placeholder that needs proper memory management
+    var result = [_]u8{0} ** 22;
+    result[0] = EIP7702_MAGIC_BYTES[0];
+    result[1] = EIP7702_MAGIC_BYTES[1];
+    @memcpy(result[2..22], &self.address);
+    return &result;
 }

Note: This implementation has lifetime issues since it returns a pointer to stack memory. Consider returning an owned array or requiring an allocator parameter.

🧹 Nitpick comments (2)
src/evm/contract/eip_7702_bytecode.zig (1)

1-1: Address the unused file status.

The file is marked as "currently unused" but is receiving documentation improvements. Consider either implementing the missing functionality to make it usable or removing it if it's not needed yet.

Would you like me to help implement the missing raw function or create an issue to track completing this module?

src/evm/error_mapping.zig (1)

12-19: Consider preserving error specificity in stack operations.

The current implementation maps StackOutOfBounds and StackInvalidPosition to StackUnderflow, which loses error specificity. Consider mapping these to their corresponding ExecutionError variants if they exist, or document why this simplification is acceptable.

πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 86c4017 and 8dfabe9.

πŸ“’ Files selected for processing (36)
  • src/evm/CLAUDE.md (3 hunks)
  • src/evm/context.zig (2 hunks)
  • src/evm/contract/bitvec.zig (1 hunks)
  • src/evm/contract/contract.zig (1 hunks)
  • src/evm/contract/eip_7702_bytecode.zig (4 hunks)
  • src/evm/error_mapping.zig (1 hunks)
  • src/evm/evm.zig (3 hunks)
  • src/evm/execution/arithmetic.zig (1 hunks)
  • src/evm/execution/bitwise.zig (1 hunks)
  • src/evm/execution/block.zig (1 hunks)
  • src/evm/execution/comparison.zig (1 hunks)
  • src/evm/execution/control.zig (1 hunks)
  • src/evm/execution/crypto.zig (3 hunks)
  • src/evm/execution/environment.zig (3 hunks)
  • src/evm/execution/execution_error.zig (3 hunks)
  • src/evm/execution/log.zig (1 hunks)
  • src/evm/execution/memory.zig (1 hunks)
  • src/evm/execution/package.zig (1 hunks)
  • src/evm/execution/stack.zig (1 hunks)
  • src/evm/execution/storage.zig (3 hunks)
  • src/evm/execution/system.zig (1 hunks)
  • src/evm/fee_market.zig (1 hunks)
  • src/evm/frame.zig (1 hunks)
  • src/evm/hardforks/chain_rules.zig (1 hunks)
  • src/evm/interpret_result.zig (1 hunks)
  • src/evm/jump_table/jump_table.zig (2 hunks)
  • src/evm/jump_table/operation_specs.zig (1 hunks)
  • src/evm/memory_size.zig (0 hunks)
  • src/evm/opcodes/opcode.zig (2 hunks)
  • src/evm/opcodes/operation.zig (2 hunks)
  • src/evm/stack/stack.zig (27 hunks)
  • src/evm/stack/stack_validation.zig (1 hunks)
  • src/evm/stack/validation_patterns.zig (1 hunks)
  • src/evm/state/state.zig (1 hunks)
  • src/evm/vm.zig (7 hunks)
  • src/evm/wasm_stubs.zig (1 hunks)
πŸ’€ Files with no reviewable changes (1)
  • src/evm/memory_size.zig
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Nx Cloud - Main Job
  • GitHub Check: CI Checks
πŸ”‡ Additional comments (48)
src/evm/fee_market.zig (1)

1-1: LGTM - Clear organizational marker during refactoring.

The TODO comment appropriately marks this module as temporarily unused during the codebase reorganization, which aligns with the PR's restructuring objectives.

src/evm/context.zig (1)

191-191: LGTM - Documentation cleanup.

Removing trailing whitespace from documentation comments improves code quality and is appropriate for this organizational refactoring.

Also applies to: 212-212

src/evm/wasm_stubs.zig (2)

1-1: LGTM - Clear integration tracking.

The TODO comment appropriately documents that WASM build integration with the real EVM is needed, which is helpful for tracking remaining work during the reorganization.


7-12: LGTM - Consistent formatting.

Reformatting the methods to use explicit braces improves code consistency without changing functionality. The no-op behavior is maintained appropriately.

src/evm/opcodes/opcode.zig (2)

37-44: LGTM - Appropriate consolidation of MemorySize struct.

Moving the MemorySize struct definition inline consolidates memory size representation into the opcode module, which aligns with the reorganization objectives. The struct maintains the same interface with offset and size fields.


328-328: LGTM - Minor whitespace cleanup.

Removing the extra blank line improves code formatting consistency.

src/evm/hardforks/chain_rules.zig (1)

3-3: Import path update looks correct
The Log module import has been updated to the parent directory, matching the new project layout.

src/evm/state/state.zig (1)

36-36: Import path update looks correct
Changing Log import to ../log.zig aligns with the reorganized directory structure.

src/evm/contract/bitvec.zig (1)

2-2: Import path update looks correct
The constants import now points to ../constants/constants.zig as intended.

src/evm/interpret_result.zig (1)

1-1: Import path update looks correct
Updated ExecutionError import to execution/execution_error.zig to reflect the new subdirectory.

src/evm/stack/validation_patterns.zig (1)

2-2: Import path update looks correct
The ExecutionError import now correctly points to ../execution/execution_error.zig.

src/evm/frame.zig (1)

3-5: Import paths updated for reorganized directory structure.
Updated Stack, Contract, and ExecutionError imports to point to their new subdirectories. Paths are correct relative to src/evm/frame.zig and align with the new layout.

src/evm/stack/stack_validation.zig (1)

3-4: Import paths adjusted for new module hierarchy.
Operation and ExecutionError imports now reference the relocated opcodes and execution directories. Paths are correct relative to this file.

src/evm/execution/stack.zig (1)

2-4: Align import paths with directory restructuring.
Operation, ExecutionError, and Stack modules are now correctly imported from their respective subdirectories (../opcodes, current directory, and ../stack). No functional impact.

src/evm/execution/arithmetic.zig (1)

55-57: Update imports to reflect new directory layout.
Operation, ExecutionError, and Stack are imported from their reorganized paths. Verified consistency with other execution modules.

src/evm/opcodes/operation.zig (2)

3-5: Correct relative imports after reorganization.
ExecutionError, Stack, and Memory imports updated to use ../ paths. Ensures module resolution aligns with the new structure.


41-41: Import ExecutionResult from updated path.
Adjusted to ../execution/execution_result.zig, matching the reorganized execution directory.

src/evm/execution/comparison.zig (1)

2-4: Import path updates reflect project reorganization.
The new import paths correctly reference the reorganized modules without altering logic.

src/evm/execution/bitwise.zig (1)

2-4: Consistent import path realignment across execution modules.
Import statements have been updated to match the new ../opcodes, execution_error, and ../stack locations.

src/evm/jump_table/operation_specs.zig (1)

2-5: Corrected module import paths for jump table.
Updated imports for execution/package.zig, constants/gas_constants.zig, stack/stack.zig, and opcodes/operation.zig align with the new directory structure.

src/evm/execution/block.zig (1)

2-4: Import paths updated to reflect directory restructure.
The new imports for Operation, ExecutionError, and Stack correctly point to their relocated modules.

src/evm/contract/contract.zig (1)

41-41: Aligned import paths with new module locations.
Updated imports for constants, ExecutionError, and Log reflect the reorganized directories without affecting functionality.

Also applies to: 44-44, 47-47

src/evm/execution/memory.zig (1)

2-7: LGTM: Import paths correctly updated for directory restructuring.

The import paths have been properly updated to reflect the new directory structure with modules organized into logical subdirectories (opcodes/, stack/, constants/). No functional changes detected.

src/evm/jump_table/jump_table.zig (1)

2-13: LGTM: Comprehensive import path updates align with directory restructuring.

All import paths have been correctly updated to reflect the new modular directory structure. The jump table functionality and opcode dispatch logic remain unchanged - these are purely organizational improvements.

Also applies to: 137-137

src/evm/execution/system.zig (1)

2-12: LGTM: Import paths properly updated for modular organization.

The import paths have been systematically updated to reflect the new directory structure with logical groupings (opcodes/, stack/, contract/, constants/, access_list/). All system operations maintain their existing functionality.

src/evm/execution/crypto.zig (1)

2-4: LGTM: Import paths updated consistently with directory restructuring.

The import paths have been properly updated to use the new modular directory structure. The inline import of memory_limits within the function is acceptable as it's only used locally within op_sha3. No functional changes to the crypto operations.

Also applies to: 31-31, 49-49

src/evm/execution/log.zig (1)

2-4: Import paths aligned with new directory layout
All module imports have been updated to reflect the reorganized folder structure. The paths for Operation, ExecutionError, Stack, and gas_constants now correctly point to their new locations without altering any logic.

Also applies to: 7-7

src/evm/execution/package.zig (1)

19-20: Re-export paths updated for core types
The Operation, ExecutionError, Stack, Contract, and gas_constants exports have been adjusted to the new nested directory structure. All re-exports remain accurate and no API surface has changed.

Also applies to: 22-22, 25-26

src/evm/execution/storage.zig (1)

2-4: Import paths updated to match new structure
The top-level imports for Operation, ExecutionError, Stack, and gas_constants now point to their relocated modules. This is purely organizational.

Also applies to: 7-7

src/evm/execution/control.zig (1)

2-5: Control op imports updated for new directory structure
All imports (Operation, ExecutionError, ExecutionResult, Stack, gas_constants, AccessList) have been correctly realigned to their new paths. No behavior changes introduced.

Also applies to: 8-9

src/evm/stack/stack.zig (3)

2-2: Corrected Log import path
The Log module now imports from the parent directory, matching the reorganized project layout.


50-56: Stack error variants renamed
The error enum entries now include a Stack prefix (StackOverflow, StackUnderflow, StackOutOfBounds, StackInvalidPosition), improving clarity and aligning with ExecutionError variants.


106-106: Method implementations updated to use renamed errors
All stack methods now return the newly prefixed Error.Stack* variants consistently. Usage across append, pop, peek, and back is correct.

Also applies to: 142-142, 178-178, 225-225

src/evm/CLAUDE.md (2)

7-16: Excellent addition of project status clarity.

This section provides crucial context for contributors about the freedom to make breaking changes and optimize without backward compatibility constraints. This will help prevent unnecessary conservative design decisions.


211-228: Well-documented performance optimization strategy.

The eager operation array analysis description is clear and provides specific implementation guidance with concrete performance benefits (50% improvement claim). The design principles are actionable and well-reasoned.

src/evm/execution/execution_error.zig (3)

4-28: Excellent documentation enhancement.

The error categorization and detailed documentation significantly improve code maintainability and developer understanding. The categorization into logical groups (normal termination, resource exhaustion, etc.) is particularly helpful.


153-154: Good descriptive error messages.

The descriptions for the new stack error variants are clear and helpful for debugging. They properly explain when each error condition occurs.


45-51:

βœ… Verification successful

Verify consistent usage of new stack error variants.

The new stack error variants (StackOutOfBounds, StackInvalidPosition) follow good naming conventions with the Stack prefix. Ensure these errors are used consistently throughout the stack implementation.


🏁 Script executed:

#!/bin/bash
# Description: Verify that the new stack error variants are used consistently
# Expected: Find usage of new error variants in stack-related files

echo "Checking usage of new stack error variants..."

# Search for the new error variants
echo "=== StackOutOfBounds usage ==="
rg "StackOutOfBounds" --type zig -A 2 -B 2

echo -e "\n=== StackInvalidPosition usage ==="
rg "StackInvalidPosition" --type zig -A 2 -B 2

echo -e "\n=== MemoryLimitExceeded usage ==="
rg "MemoryLimitExceeded" --type zig -A 2 -B 2

# Check if old error names are still being used
echo -e "\n=== Checking for old error names that should be updated ==="
rg "OutOfBounds|InvalidPosition" --type zig src/evm/stack/ || echo "No old error names found in stack module"

Length of output: 25045


New stack error variants are used consistently

Verified that StackOutOfBounds and StackInvalidPosition are referenced uniformly across:
β€’ src/evm/stack/stack.zig (all boundary checks use the new variants)
β€’ src/evm/execution/execution_error.zig (both variants are listed and have matching messages)
β€’ src/evm/error_mapping.zig (both map correctly)

No lingering references to old error names remain.

src/evm/execution/environment.zig (2)

2-11: LGTM!

Import path changes correctly reflect the new directory structure.


156-156: Good simplification of memory operations.

The direct calls to frame.memory.set_data_bounded reduce indirection while maintaining proper error handling through the try expression.

Also applies to: 309-309

src/evm/vm.zig (4)

2-23: LGTM!

Import path updates correctly reflect the new directory structure.


50-50: Verify the need for u32 depth.

The change from u16 to u32 for the depth field increases the maximum depth from 65,535 to over 4 billion. Given that the EVM typically enforces a maximum call depth of 1024, even u16 provides significant headroom. Is there a specific requirement driving this change?


128-128: Good type rename for clarity.

The rename from RunResult to InterpretResult better describes the purpose of the type and improves code readability.

Also applies to: 135-135, 142-142, 183-183, 193-193, 196-196, 199-199, 202-202, 214-214, 228-234


220-220: Nice simplification of PC update logic.

The conditional expression is more concise while maintaining the same behavior.

src/evm/error_mapping.zig (4)

8-10: Good documentation update.

The simplified documentation clearly describes the module's purpose.


32-42: Good improvement to memory error mapping.

The function now correctly maps MemoryLimitExceeded to its corresponding ExecutionError variant instead of OutOfGas, and the anyerror parameter provides better flexibility.


52-77: Excellent type safety improvement.

Replacing anytype with concrete Address.Address type in VM storage functions improves type safety and makes the API clearer.


80-105: Consistent error handling pattern.

All memory helper functions now use a uniform pattern of inline error mapping, which improves code consistency and maintainability.

Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 8dfabe9 and df805ec.

πŸ“’ Files selected for processing (81)
  • Cargo.toml (1 hunks)
  • build.zig (29 hunks)
  • src/address/address.zig (1 hunks)
  • src/block/block.zig (1 hunks)
  • src/compilers/rust_build.zig (5 hunks)
  • src/evm/access_list/access_list.zig (1 hunks)
  • src/evm/access_list/access_list_storage_key.zig (1 hunks)
  • src/evm/context.zig (3 hunks)
  • src/evm/contract/contract.zig (1 hunks)
  • src/evm/contract/eip_7702_bytecode.zig (4 hunks)
  • src/evm/create_result.zig (1 hunks)
  • src/evm/error_mapping.zig (1 hunks)
  • src/evm/evm.zig (3 hunks)
  • src/evm/execution/block.zig (1 hunks)
  • src/evm/execution/control.zig (1 hunks)
  • src/evm/execution/environment.zig (3 hunks)
  • src/evm/execution/log.zig (1 hunks)
  • src/evm/execution/storage.zig (3 hunks)
  • src/evm/execution/system.zig (1 hunks)
  • src/evm/jump_table/jump_table.zig (2 hunks)
  • src/evm/state/evm_log.zig (1 hunks)
  • src/evm/state/state.zig (1 hunks)
  • src/evm/state/storage_key.zig (1 hunks)
  • src/evm/vm.zig (7 hunks)
  • src/rlp/rlp.zig (1 hunks)
  • src/root.zig (1 hunks)
  • src/root_wasm.zig (1 hunks)
  • src/solidity/snail_tracer_test.zig (1 hunks)
  • src/trie/hash_builder.zig (1 hunks)
  • src/trie/hash_builder_complete.zig (1 hunks)
  • src/trie/hash_builder_fixed.zig (1 hunks)
  • src/trie/merkle_trie.zig (1 hunks)
  • src/trie/optimized_branch.zig (1 hunks)
  • src/trie/proof.zig (1 hunks)
  • src/trie/trie.zig (1 hunks)
  • test/evm/error_mapping_test.zig (2 hunks)
  • test/evm/gas/gas_accounting_test.zig (1 hunks)
  • test/evm/integration/arithmetic_flow_test.zig (1 hunks)
  • test/evm/integration/arithmetic_sequences_test.zig (1 hunks)
  • test/evm/integration/basic_sequences_test.zig (1 hunks)
  • test/evm/integration/call_environment_test.zig (1 hunks)
  • test/evm/integration/complex_interactions_test.zig (1 hunks)
  • test/evm/integration/complex_scenarios_test.zig (1 hunks)
  • test/evm/integration/comprehensive_test.zig (1 hunks)
  • test/evm/integration/contract_interaction_test.zig (1 hunks)
  • test/evm/integration/control_flow_test.zig (1 hunks)
  • test/evm/integration/crypto_logging_test.zig (1 hunks)
  • test/evm/integration/edge_cases_test.zig (1 hunks)
  • test/evm/integration/environment_system_test.zig (1 hunks)
  • test/evm/integration/event_logging_test.zig (1 hunks)
  • test/evm/integration/memory_storage_test.zig (1 hunks)
  • test/evm/integration/opcode_integration_test.zig (1 hunks)
  • test/evm/jump_table_test.zig (1 hunks)
  • test/evm/memory_comparison_test.zig (1 hunks)
  • test/evm/memory_limit_test.zig (1 hunks)
  • test/evm/memory_stress_test.zig (1 hunks)
  • test/evm/memory_test.zig (1 hunks)
  • test/evm/opcodes/arithmetic_test.zig (1 hunks)
  • test/evm/opcodes/bitwise_test.zig (1 hunks)
  • test/evm/opcodes/block_test.zig (1 hunks)
  • test/evm/opcodes/comparison_comprehensive_test.zig (1 hunks)
  • test/evm/opcodes/comparison_edge_cases_test.zig (1 hunks)
  • test/evm/opcodes/comparison_test.zig (1 hunks)
  • test/evm/opcodes/control_system_comprehensive_test.zig (1 hunks)
  • test/evm/opcodes/control_test.zig (1 hunks)
  • test/evm/opcodes/create_call_comprehensive_test.zig (1 hunks)
  • test/evm/opcodes/crypto_test.zig (1 hunks)
  • test/evm/opcodes/environment_test.zig (1 hunks)
  • test/evm/opcodes/log_test.zig (1 hunks)
  • test/evm/opcodes/memory_test.zig (1 hunks)
  • test/evm/opcodes/stack_test.zig (1 hunks)
  • test/evm/opcodes/storage_comprehensive_test.zig (1 hunks)
  • test/evm/opcodes/storage_test.zig (1 hunks)
  • test/evm/opcodes/system_test.zig (1 hunks)
  • test/evm/opcodes/test_helpers.zig (1 hunks)
  • test/evm/shared_memory_test.zig (1 hunks)
  • test/evm/stack_batched_test.zig (1 hunks)
  • test/evm/stack_test.zig (3 hunks)
  • test/evm/stack_validation_test.zig (1 hunks)
  • test/evm/static_call_protection_test.zig (1 hunks)
  • test/evm/vm_opcode_test.zig (1 hunks)
βœ… Files skipped from review due to trivial changes (66)
  • src/evm/access_list/access_list.zig
  • src/evm/create_result.zig
  • src/root_wasm.zig
  • src/evm/state/storage_key.zig
  • src/block/block.zig
  • src/address/address.zig
  • src/evm/access_list/access_list_storage_key.zig
  • src/trie/hash_builder_fixed.zig
  • src/trie/optimized_branch.zig
  • test/evm/memory_stress_test.zig
  • test/evm/opcodes/stack_test.zig
  • src/trie/hash_builder.zig
  • test/evm/opcodes/storage_test.zig
  • src/solidity/snail_tracer_test.zig
  • test/evm/integration/crypto_logging_test.zig
  • test/evm/memory_limit_test.zig
  • test/evm/integration/edge_cases_test.zig
  • test/evm/opcodes/memory_test.zig
  • test/evm/integration/arithmetic_flow_test.zig
  • test/evm/shared_memory_test.zig
  • test/evm/integration/environment_system_test.zig
  • test/evm/opcodes/storage_comprehensive_test.zig
  • src/trie/merkle_trie.zig
  • test/evm/integration/basic_sequences_test.zig
  • test/evm/static_call_protection_test.zig
  • test/evm/opcodes/control_test.zig
  • test/evm/opcodes/create_call_comprehensive_test.zig
  • test/evm/opcodes/test_helpers.zig
  • src/rlp/rlp.zig
  • test/evm/memory_comparison_test.zig
  • Cargo.toml
  • test/evm/opcodes/comparison_edge_cases_test.zig
  • test/evm/integration/control_flow_test.zig
  • test/evm/opcodes/environment_test.zig
  • test/evm/integration/opcode_integration_test.zig
  • test/evm/stack_batched_test.zig
  • test/evm/opcodes/block_test.zig
  • test/evm/integration/comprehensive_test.zig
  • test/evm/opcodes/crypto_test.zig
  • src/evm/state/evm_log.zig
  • test/evm/integration/event_logging_test.zig
  • test/evm/integration/complex_interactions_test.zig
  • test/evm/integration/call_environment_test.zig
  • src/trie/trie.zig
  • test/evm/opcodes/log_test.zig
  • src/trie/hash_builder_complete.zig
  • src/trie/proof.zig
  • test/evm/integration/arithmetic_sequences_test.zig
  • test/evm/stack_validation_test.zig
  • test/evm/gas/gas_accounting_test.zig
  • test/evm/opcodes/bitwise_test.zig
  • src/root.zig
  • test/evm/opcodes/control_system_comprehensive_test.zig
  • test/evm/opcodes/system_test.zig
  • src/compilers/rust_build.zig
  • test/evm/jump_table_test.zig
  • test/evm/integration/contract_interaction_test.zig
  • test/evm/opcodes/arithmetic_test.zig
  • test/evm/integration/memory_storage_test.zig
  • test/evm/opcodes/comparison_test.zig
  • test/evm/opcodes/comparison_comprehensive_test.zig
  • test/evm/vm_opcode_test.zig
  • src/evm/execution/log.zig
  • src/evm/evm.zig
  • test/evm/memory_test.zig
  • build.zig
🚧 Files skipped from review as they are similar to previous changes (11)
  • src/evm/context.zig
  • src/evm/state/state.zig
  • src/evm/execution/block.zig
  • src/evm/execution/system.zig
  • src/evm/contract/contract.zig
  • src/evm/jump_table/jump_table.zig
  • src/evm/execution/control.zig
  • src/evm/contract/eip_7702_bytecode.zig
  • src/evm/execution/storage.zig
  • src/evm/execution/environment.zig
  • src/evm/vm.zig
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: CI Checks
  • GitHub Check: Nx Cloud - Main Job
  • GitHub Check: Analyze (javascript-typescript)
πŸ”‡ Additional comments (8)
test/evm/integration/complex_scenarios_test.zig (1)

3-3: LGTM! Clean import path update aligns with reorganization.

The import path change from "evm" to "tevm/evm" correctly reflects the new directory structure as part of the codebase reorganization. All subsequent usage of the imported module remains unchanged, maintaining test functionality.

test/evm/stack_test.zig (1)

3-3: Import path correctly updated.

The import path change from "evm" to "tevm/evm" aligns with the new directory structure.

test/evm/error_mapping_test.zig (1)

3-3: Import path and error variant correctly updated.

Both changes are consistent with the refactoring:

  • Import path updated to "tevm/evm"
  • Error variant renamed to Stack.Error.StackUnderflow

Also applies to: 120-120

src/evm/error_mapping.zig (5)

2-6: Import paths correctly updated to reflect new directory structure.

The imports now properly reference the reorganized module paths under the new directory layout.


11-19: Clean refactoring of stack_pop with inline error mapping.

The inline error translation is more concise than separate mapping functions, and the error variants are correctly updated.


31-42: Good defensive error handling with anyerror type.

The generalization to handle any error type with a fallback to OutOfMemory is a solid defensive programming practice. The new MemoryLimitExceeded mapping is correctly added.


79-105: Well-structured memory helper functions with consistent error mapping.

All memory helper functions follow a clean pattern of delegating to the underlying Memory methods and consistently mapping errors through map_memory_error. This provides good abstraction and error handling.


52-63:

βœ… Verification successful

Good type safety improvement, but verify error handling coverage.

The change from anytype to concrete Address.Address type improves type safety. However, the error handling only catches OutOfMemory - ensure this covers all possible errors from the storage operations.

Let me verify what errors the storage operations can throw:

Also applies to: 66-77


🏁 Script executed:

#!/bin/bash
# Search for set_storage and set_transient_storage implementations
ast-grep --pattern 'pub fn set_storage($$$) $$ {
  $$$
}'

ast-grep --pattern 'pub fn set_transient_storage($$$) $$ {
  $$$
}'

# Also search in the state module
rg "fn set_(transient_)?storage" src/evm/state -A 5

Length of output: 1059


Error handling for storage operations is exhaustive

The set_storage and set_transient_storage methods on EvmState both return std.mem.Allocator.Error!void, and std.mem.Allocator.Error currently only defines OutOfMemory. The existing catch(err) { switch (err) { OutOfMemory => ExecutionError.Error.OutOfMemory } } covers all possible error cases. No additional error branches are neededβ€”code changes can be approved.

@@ -42,7 +42,7 @@ test "Stack: basic push and pop operations" {
try testing.expect(stack.isEmpty());

// Pop from empty stack should error
try testing.expectError(Stack.Error.Underflow, stack.pop());
try testing.expectError(Stack.Error.StackUnderflow, stack.pop());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ’‘ Verification agent

🧩 Analysis chain

Error variant names correctly updated.

The changes from Stack.Error.Underflow to Stack.Error.StackUnderflow are consistent with the renamed stack error variants.

I notice that other stack error variants like Stack.Error.OutOfBounds, Stack.Error.Overflow, and Stack.Error.InvalidPosition haven't been renamed with the Stack prefix. Let me verify if this is intentional:

Also applies to: 457-457


🏁 Script executed:

#!/bin/bash
# Check all stack error variant definitions and usage patterns
ast-grep --pattern 'Error = error {
  $$$
}'

# Also search for all Stack.Error usage to see the full pattern
rg "Stack\.Error\." -A 1 -B 1

Length of output: 7690


🏁 Script executed:

#!/usr/bin/env bash
# Locate the definition of the Stack.Error enum to confirm which variants exist
set -e

# Search for the Error declaration in Zig files
rg -n --include "*.zig" "pub const Error = error" -A3 -B3
rg -n --include "*.zig" "const Error = error" -A3 -B3

Length of output: 510


🏁 Script executed:

#!/usr/bin/env bash
set -e

# Search for all error enum definitions in Zig files
rg -n -g '*.zig' 'Error = error' -A5 -B5

Length of output: 13235


Ensure consistent prefixing of all Stack.Error variants

The rename from Underflow to StackUnderflow is correct, but other variants are referenced inconsistently across the codebase. Please align all uses to match the enum declared in src/evm/stack/stack.zig (StackOverflow, StackUnderflow, StackOutOfBounds, StackInvalidPosition):

β€’ src/evm/stack/stack.zig
– Verify the enum reads:
zig pub const Error = error{ StackOverflow, StackUnderflow, StackOutOfBounds, StackInvalidPosition, };

β€’ src/evm/error_mapping.zig
– Already matches the Stack* prefixes. No change needed here.

β€’ test/evm/stack_batched_test.zig

  • Change all Stack.Error.OutOfBounds β†’ Stack.Error.StackOutOfBounds
  • Change Stack.Error.Overflow β†’ Stack.Error.StackOverflow

β€’ test/evm/stack_test.zig

  • Update Stack.Error.Overflow β†’ Stack.Error.StackOverflow
  • Update all Stack.Error.OutOfBounds β†’ Stack.Error.StackOutOfBounds
  • Update Stack.Error.InvalidPosition β†’ Stack.Error.StackInvalidPosition

β€’ test/evm/error_mapping_test.zig

  • Change Stack.Error.Overflow β†’ Stack.Error.StackOverflow
  • Change Stack.Error.OutOfBounds β†’ Stack.Error.StackOutOfBounds
  • Change Stack.Error.InvalidPosition β†’ Stack.Error.StackInvalidPosition

Aligning these references will ensure the code compiles and that all stack error variants consistently carry the Stack prefix.

πŸ€– Prompt for AI Agents
In test/evm/stack_test.zig around line 45, update all references to stack error
variants to include the Stack prefix consistently. Change Stack.Error.Overflow
to Stack.Error.StackOverflow, Stack.Error.OutOfBounds to
Stack.Error.StackOutOfBounds, and Stack.Error.InvalidPosition to
Stack.Error.StackInvalidPosition to match the enum declared in
src/evm/stack/stack.zig. Apply similar updates in
test/evm/stack_batched_test.zig and test/evm/error_mapping_test.zig as described
to ensure uniform naming across the codebase.

Comment on lines 21 to 65
/// Push a value to the stack with proper error mapping
pub fn stack_push(stack: *Stack, value: u256) ExecutionError.Error!void {
return stack.append(value) catch |err| switch (err) {
Stack.Error.StackOverflow => ExecutionError.Error.StackOverflow,
Stack.Error.StackUnderflow => ExecutionError.Error.StackUnderflow,
Stack.Error.StackOutOfBounds => ExecutionError.Error.StackUnderflow,
Stack.Error.StackInvalidPosition => ExecutionError.Error.StackUnderflow,
};
}
8000 Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ’‘ Verification agent

🧩 Analysis chain

Verify error handling in stack_push.

The inline error mapping is good, but handling StackUnderflow, StackOutOfBounds, and StackInvalidPosition errors in a push operation seems unnecessary. The append() function should only throw StackOverflow.

Let me verify what errors the Stack.append() function can actually throw:


🏁 Script executed:

#!/bin/bash
# Search for the append function definition in Stack
ast-grep --pattern 'pub fn append($$$) $$ {
  $$$
}'

# Also check for append_unsafe and any error returns in stack implementation
rg "fn append" src/evm/stack -A 10

Length of output: 1377


Simplify stack_push error mapping to only handle StackOverflow

Stack.append in src/evm/stack/stack.zig only returns Error.StackOverflow. The other cases (StackUnderflow, StackOutOfBounds, StackInvalidPosition) can never occur on a push. Please remove the redundant arms:

β€’ File: src/evm/error_mapping.zig
Lines: ~21–29

Proposed change:

 pub fn stack_push(stack: *Stack, value: u256) ExecutionError.Error!void {
-    return stack.append(value) catch |err| switch (err) {
-        Stack.Error.StackOverflow => ExecutionError.Error.StackOverflow,
-        Stack.Error.StackUnderflow => ExecutionError.Error.StackUnderflow,
-        Stack.Error.StackOutOfBounds => ExecutionError.Error.StackUnderflow,
-        Stack.Error.StackInvalidPosition => ExecutionError.Error.StackUnderflow,
-    };
+    return stack.append(value) catch |Stack.Error.StackOverflow| => 
+        ExecutionError.Error.StackOverflow;
 }
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/// Push a value to the stack with proper error mapping
pub fn stack_push(stack: *Stack, value: u256) ExecutionError.Error!void {
return stack.append(value) catch |err| switch (err) {
Stack.Error.StackOverflow => ExecutionError.Error.StackOverflow,
Stack.Error.StackUnderflow => ExecutionError.Error.StackUnderflow,
Stack.Error.StackOutOfBounds => ExecutionError.Error.StackUnderflow,
Stack.Error.StackInvalidPosition => ExecutionError.Error.StackUnderflow,
};
}
/// Push a value to the stack with proper error mapping
pub fn stack_push(stack: *Stack, value: u256) ExecutionError.Error!void {
return stack.append(value) catch |Stack.Error.StackOverflow| => ExecutionError.Error.StackOverflow;
}
πŸ€– Prompt for AI Agents
In src/evm/error_mapping.zig around lines 21 to 29, the stack_push function's
error handling includes cases for StackUnderflow, StackOutOfBounds, and
StackInvalidPosition, which cannot occur during a push operation as Stack.append
only throws StackOverflow. Simplify the error mapping by removing these
redundant error cases and only handle StackOverflow in the catch block.

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.

1 participant
0