Skip to content

refactor(levm): removed call frame as parameter from certain functions #2645

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 12 commits into from

Conversation

SDartayet
Copy link
Contributor

@SDartayet SDartayet commented Apr 29, 2025

Motivation

Simplify some function calls by removing unnecessary parameters and make the code of the handlers a bit more readable.

Description

The current call frame was being passed as a parameter to certain function calls in the VM. This removes it in favor of using the VM method. Some variables are also renamed for further clarity, and the responsability of popping the current call frame from the stack is delegated to the handle_return_call and handle_return_create methods (where both the call frame that has just been executed, and the one to be returned to, are needed).

Resolves #2542 and #2569

Copy link

github-actions bot commented Apr 29, 2025

Lines of code report

Total lines added: 5
Total lines removed: 13
Total lines changed: 18

Detailed view
+-----------------------------------------------------+-------+------+
| File                                                | Lines | Diff |
+-----------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/execution_handlers.rs     | 237   | +4   |
+-----------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/opcode_handlers/system.rs | 843   | +1   |
+-----------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/vm.rs                     | 359   | -13  |
+-----------------------------------------------------+-------+------+

Copy link

github-actions bot commented Apr 29, 2025

EF Tests Comparison

Test Name MAIN PR DIFF
Summary: 32725/38385 (85.25%) 32722/38385 (85.25%) ⬇️️ -3
Prague: 5202/5202 (100.00%) 5202/5202 (100.00%) ➖️
Cancun: 7608/7608 (100.00%) 7608/7608 (100.00%) ➖️
Shanghai: 3214/3214 (100.00%) 3214/3214 (100.00%) ➖️
Paris: 2886/2886 (100.00%) 2886/2886 (100.00%) ➖️
London: 2870/2915 (98.46%) 2870/2915 (98.46%) ➖️
Berlin: 215/2755 (7.80%) 215/2755 (7.80%) ➖️
Istanbul: 238/2709 (8.79%) 238/2709 (8.79%) ➖️
Petersburg: 2490/2564 (97.11%) 2490/2564 (97.11%) ➖️
Constantinople: 2312/2428 (95.22%) 2312/2428 (95.22%) ➖️
Byzantium: 2429/2492 (97.47%) 2429/2492 (97.47%) ➖️
SpuriousDragon: 567/598 (94.82%) 567/598 (94.82%) ➖️
Tangerine: 570/669 (85.20%) 569/669 (85.05%) ⬇️️ -1
Homestead: 1354/1465 (92.42%) 1353/1465 (92.35%) ⬇️️ -1
Frontier: 770/880 (87.50%) 769/880 (87.39%) ⬇️️ -1

Copy link

github-actions bot commented Apr 29, 2025

Benchmark Results Comparison

PR Results

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Factorial 238.2 ± 1.3 236.8 241.5 1.00
levm_Factorial 888.9 ± 7.4 882.3 902.7 3.73 ± 0.04

Benchmark Results: Factorial - Recursive

Command Mean [s] Min [s] Max [s] Relative
revm_FactorialRecursive 1.523 ± 0.100 1.414 1.644 1.00
levm_FactorialRecursive 13.340 ± 0.223 13.107 13.585 8.76 ± 0.59

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Fibonacci 208.2 ± 1.4 205.0 209.7 1.00
levm_Fibonacci 888.9 ± 10.2 879.1 907.7 4.27 ± 0.06

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ManyHashes 8.7 ± 0.1 8.6 8.8 1.00
levm_ManyHashes 17.4 ± 0.3 17.2 18.2 2.00 ± 0.04

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
revm_BubbleSort 3.264 ± 0.010 3.251 3.279 1.00
levm_BubbleSort 5.741 ± 0.048 5.679 5.833 1.76 ± 0.02

Benchmark Results: ERC20 - Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Transfer 251.7 ± 3.2 249.0 259.3 1.00
levm_ERC20Transfer 506.0 ± 4.1 501.1 513.6 2.01 ± 0.03

Benchmark Results: ERC20 - Mint

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Mint 144.1 ± 1.0 142.8 146.7 1.00
levm_ERC20Mint 322.0 ± 5.3 317.0 335.5 2.23 ± 0.04

Benchmark Results: ERC20 - Approval

Command Mean [s] Min [s] Max [s] Relative
revm_ERC20Approval 1.041 ± 0.011 1.028 1.062 1.00
levm_ERC20Approval 1.919 ± 0.015 1.899 1.939 1.84 ± 0.02

Main Results

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Factorial 245.9 ± 5.3 241.3 257.3 1.00
levm_Factorial 881.5 ± 7.4 872.7 893.0 3.59 ± 0.08

Benchmark Results: Factorial - Recursive

Command Mean [s] Min [s] Max [s] Relative
revm_FactorialRecursive 1.484 ± 0.096 1.356 1.600 1.00
levm_FactorialRecursive 13.188 ± 0.184 12.971 13.377 8.89 ± 0.59

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Fibonacci 210.5 ± 1.0 209.5 212.9 1.00
levm_Fibonacci 877.4 ± 9.4 869.3 896.1 4.17 ± 0.05

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ManyHashes 8.8 ± 0.0 8.8 8.9 1.00
levm_ManyHashes 17.8 ± 0.2 17.5 18.1 2.03 ± 0.03

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
revm_BubbleSort 3.300 ± 0.070 3.261 3.491 1.00
levm_BubbleSort 5.739 ± 0.030 5.710 5.807 1.74 ± 0.04

Benchmark Results: ERC20 - Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Transfer 254.6 ± 3.5 251.2 263.3 1.00
levm_ERC20Transfer 509.9 ± 6.3 503.3 525.6 2.00 ± 0.04

Benchmark Results: ERC20 - Mint

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Mint 145.4 ± 2.2 143.1 149.8 1.00
levm_ERC20Mint 326.0 ± 4.2 320.8 333.6 2.24 ± 0.04

Benchmark Results: ERC20 - Approval

Command Mean [s] Min [s] Max [s] Relative
revm_ERC20Approval 1.058 ± 0.013 1.041 1.084 1.00
levm_ERC20Approval 1.940 ± 0.012 1.921 1.955 1.83 ± 0.03

@SDartayet SDartayet force-pushed the call-frame-parameter-refactor branch from 4ee8c2f to 3791861 Compare April 30, 2025 15:21
@SDartayet SDartayet marked this pull request as ready for review April 30, 2025 18:42
@SDartayet SDartayet requested a review from a team as a code owner April 30, 2025 18:42
@SDartayet SDartayet marked this pull request as draft April 30, 2025 19:21
@SDartayet SDartayet marked this pull request as ready for review May 5, 2025 19:33
Copy link
Contributor

@JereSalo JereSalo left a comment

Choose a reason for hiding this comment

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

  • I think it's best to rename current_call_frame to executed_call_frame in scenarios in which the callframe has already been executed. Like in handle_opcode_result.
  • To be honest, I actually think that it is a little bit more clear if we pop the callframe in run_execution and send it as parameter, otherwise it is confusing when seeing self.current_call_frame_mut() being called without knowing the callframe was popped.
  • call_frame_to_execute is not a bad name but may be misleading. In that context maybe parent_call_frame is a more accurate name and the executed one could be executed_call_frame.

My take on this is that maybe the best thing to do is leave the callframe as argument in those functions so that the popping of the callframe is clear in run_execution (so that the execution flow is more clear) and only change the names of the callframes to the ones suggested: parent_call_frame and executed_call_frame.
This is just my opinion, maybe I'm biased and I don't see the decrease of complexity in this PR. Perhaps it should be also reviewed by somebody else.

@SDartayet SDartayet closed this May 7, 2025
@JereSalo
Copy link
Contributor

JereSalo commented May 7, 2025

This was closed because it added unwanted complexity. Some things will be implemented in another PRs, like name improvements and maybe some comments explaining confusing parts of the code regarding to callframes.

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.

2 participants