Skip to content

Add MUL and DIV operations for EVM v2 with JMH benchmarks#10178

Closed
parthdagia05 wants to merge 1 commit intobesu-eth:mainfrom
parthdagia05:feat/evm-v2-mul-div
Closed

Add MUL and DIV operations for EVM v2 with JMH benchmarks#10178
parthdagia05 wants to merge 1 commit intobesu-eth:mainfrom
parthdagia05:feat/evm-v2-mul-div

Conversation

@parthdagia05
Copy link
Copy Markdown

@parthdagia05 parthdagia05 commented Apr 3, 2026

Description

Continues the EVM v2 implementation started in #10105 and follows the pattern established in #10154.
This PR adds the MUL (0x02) and DIV (0x04) arithmetic opcodes to the EVM v2 long[]-based stack.

Changes

  • Implement MUL (0x02) and DIV (0x04) opcodes for the EVM v2 long[]-based stack, with zero heap allocation on the hot path
  • Add MulOperationV2 and DivOperationV2 operation classes utilizing StackArithmetic for 256-bit arithmetic directly on the flat long[] operand stack
  • Add JMH benchmarks (MulOperationBenchmarkV2, DivOperationBenchmarkV2) for both operations

Benchmarks

Baseline (v1 on main)

Benchmark (caseName) Mode Cnt Score Error Units
MulOperationBenchmark.executeOperation N/A avgt 15 225.036 ± 22.024 ns/op
DivOperationBenchmark.executeOperation DIV_FULL_RANDOM avgt 15 215.429 ± 135.653 ns/op

With this PR (v2)

Benchmark (caseName) Mode Cnt Score Error Units
MulOperationBenchmarkV2.executeOperation N/A avgt 15 58.162 ± 4.659 ns/op
DivOperationBenchmarkV2.executeOperation N/A avgt 15 53.422 ± 3.602 ns/op

Summary

Operation v1 (ns/op) v2 (ns/op) Speedup
MUL 225.036 58.162 ~3.9x faster
DIV 215.429 53.422 ~4.0x faster

V2 also shows significantly lower variance, indicating more consistent performance.

Thanks for sending a pull request! Have you done the following?

  • Checked out our contribution guidelines?
  • Considered documentation and added the doc-change-required label to this PR if updates are required.
  • Considered the changelog and included an update if required.
  • For database changes (e.g. KeyValueSegmentIdentifier) considered compatibility and performed forwards and backwards compatibility tests

Locally, you can run these tests to catch failures early:

  • spotless: ./gradlew spotlessApply
  • unit tests: ./gradlew build
  • acceptance tests: ./gradlew acceptanceTest
  • integration tests: ./gradlew integrationTest
  • reference tests: ./gradlew ethereum:referenceTests:referenceTests
  • hive tests: Engine or other RPCs modified?

Implements MulOperationV2 and DivOperationV2 using the v2 stack data layout,
along with corresponding JMH benchmarks showing ~4x performance improvement
over v1 implementations.

Signed-off-by: Parth Dagia <parth.24bcs10414@sst.scaler.com>
@parthdagia05 parthdagia05 force-pushed the feat/evm-v2-mul-div branch from cf4b89e to 1783bfe Compare April 3, 2026 19:10
@ahamlat ahamlat closed this Apr 10, 2026
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