Add POP, PUSH0 and PUSH1-32 operations for EVM v2 (#10131)#10209
Open
vivek-0509 wants to merge 1 commit intobesu-eth:mainfrom
Open
Add POP, PUSH0 and PUSH1-32 operations for EVM v2 (#10131)#10209vivek-0509 wants to merge 1 commit intobesu-eth:mainfrom
vivek-0509 wants to merge 1 commit intobesu-eth:mainfrom
Conversation
Signed-off-by: Vivek Singh Solanki <viveksolanki0509@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixed Issue(s)
Partially addresses #10131 (Category 6: Stack manipulation ops)
Summary
Implements POP (0x50), PUSH0 (0x5F), and PUSH1-PUSH32 (0x60-0x7F) operations for the EVM v2
long[]stack, covering 34 opcodes that account for ~30% of all EVM instructions executed on mainnet.Changes
New operations:
PopOperationV2- decrements stack pointer (gas: 2, baseTier)Push0OperationV2- pushes 4 zero longs (gas: 2, baseTier, Shanghai-gated)PushOperationV2- reads immediate bytes from bytecode into 4-limblong[]representation (gas: 3, veryLowTier)Performance optimizations (inspired by Geth's #19210, #31267):
staticPush1/staticPush2methods with dedicated dispatch cases, avoiding the genericpushFromBytespath for the two most frequently executed PUSH variants (~21% of all instructions combined)bytesToLongreads (nobuildLongloop)Infrastructure additions:
MessageFrame.stackHasSpace(int n)- overflow check for push operationsAbstractFixedCostOperationV2.OVERFLOW_RESPONSE- static shared response for overflowStackArithmetic.push1(),push2(),pushZero(),pushFromBytes()- stack manipulation utilities with VarHandle for fast big-endian byte readsBenchmark Results
Note: Benchmarks run with
-f 0(non-forked, same VM). The v1 PUSH32 number appears fast becauseBytes.wrapis a zero-copy reference that defers byte interpretation to arithmetic time - v2 pays the conversion cost upfront at push time, yielding zero-allocation arithmetic downstream.Known optimization opportunity
stackHasSpace()callsgetMaxStackSize()->txValues.maxStackSize()on every PUSH. This indirection was flagged by @daniellehrner in #10105 as a potential JIT inlining concern. CachingmaxStackSizeas a field onMessageFramewould reduce this, but is left for the maintainers to decide as it affects the broader v2 architecture.Thanks for sending a pull request! Have you done the following?
doc-change-requiredlabel to this PR if updates are required.Locally, you can run these tests to catch failures early:
./gradlew spotlessApply./gradlew build./gradlew acceptanceTest./gradlew integrationTest./gradlew ethereum:referenceTests:referenceTests