Skip to content

Add SDIV, MOD, SMOD, ADDMOD, EXP and SIGNEXTEND operations for EVM v2#10186

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

Add SDIV, MOD, SMOD, ADDMOD, EXP and SIGNEXTEND operations for EVM v2#10186
parthdagia05 wants to merge 1 commit intobesu-eth:mainfrom
parthdagia05:feat/evm-v2-remaining-arithmetic

Conversation

@parthdagia05
Copy link
Copy Markdown

@parthdagia05 parthdagia05 commented Apr 4, 2026

PR description

Continues the EVM v2 implementation started in #10105 and follows the pattern established in #10154 and #10171.
This PR adds the remaining arithmetic opcodes to the EVM v2 long[]-based stack: SDIV (0x05), MOD (0x06), SMOD (0x07), ADDMOD (0x08), EXP (0x0a), and SIGNEXTEND (0x0b).

Changes

  • Implement SDIV (0x05), MOD (0x06), SMOD (0x07), ADDMOD (0x08), EXP (0x0a), and SIGNEXTEND (0x0b) opcodes for the EVM v2 long[]-based stack, with zero heap allocation on the hot path
  • Add SDivOperationV2, ModOperationV2, SModOperationV2, AddModOperationV2, ExpOperationV2, and SignExtendOperationV2 operation classes utilizing UInt256 for 256-bit arithmetic directly on the flat long[] operand stack
  • Add TernaryOperationBenchmarkV2 base class for benchmarking ternary operations (3 inputs → 1 output)
  • Add JMH benchmarks for all six operations

Benchmarks

Baseline (v1 on main)

Benchmark (caseName) Mode Cnt Score Error Units
SDivOperationBenchmark.executeOperation SDIV_FULL_RANDOM avgt 15 114.672 ± 2.897 ns/op
ModOperationBenchmark.executeOperation FULL_RANDOM avgt 15 107.074 ± 6.765 ns/op
SModOperationBenchmark.executeOperation FULL_RANDOM avgt 15 127.728 ± 12.489 ns/op
AddModOperationBenchmark.executeOperation FULL_RANDOM avgt 15 156.767 ± 16.190 ns/op
ExpOperationBenchmark.executeOperation N/A avgt 15 10313.733 ± 1294.918 ns/op
SignExtendOperationBenchmark.executeOperation N/A avgt 15 70.865 ± 6.442 ns/op

With this PR (v2)

Benchmark Mode Cnt Score Error Units
SDivOperationBenchmarkV2.executeOperation avgt 15 64.162 ± 4.224 ns/op
ModOperationBenchmarkV2.executeOperation avgt 15 64.207 ± 8.703 ns/op
SModOperationBenchmarkV2.executeOperation avgt 15 68.933 ± 3.234 ns/op
AddModOperationBenchmarkV2.executeOperation avgt 15 116.354 ± 32.339 ns/op
ExpOperationBenchmarkV2.executeOperation avgt 15 8557.310 ± 768.777 ns/op
SignExtendOperationBenchmarkV2.executeOperation avgt 15 24.186 ± 2.781 ns/op

Summary

Operation v1 (ns/op) v2 (ns/op) Speedup
SDIV 114.672 64.162 ~1.8x faster
MOD 107.074 64.207 ~1.7x faster
SMOD 127.728 68.933 ~1.9x faster
ADDMOD 156.767 116.354 ~1.3x faster
EXP 10313.733 8557.310 ~1.2x faster
SIGNEXTEND 70.865 24.186 ~2.9x faster

Fixed Issue(s)

fixes #10131

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?

… with JMH benchmarks

Implements the remaining arithmetic opcodes for the EVM v2 long[]-based stack,
with zero heap allocation on the hot path. Includes JMH benchmarks showing
1.2x-2.9x performance improvement over v1 implementations.

Signed-off-by: Parth Dagia <parth.24bcs10414@sst.scaler.com>
@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.

EVM V2 - Stack Long Array Skeleton

2 participants