Skip to content

Optimise CALL by throwing stack underflow earlier#9581

Merged
Marchhill merged 2 commits intomasterfrom
optimise-stack-underflow-call
Nov 3, 2025
Merged

Optimise CALL by throwing stack underflow earlier#9581
Marchhill merged 2 commits intomasterfrom
optimise-stack-underflow-call

Conversation

@Marchhill
Copy link
Copy Markdown
Contributor

@Marchhill Marchhill commented Oct 27, 2025

Changes

  • Pop from stack at start of instruction to fail faster without having to access state etc. Also better matches spec

Types of changes

What types of changes does your code introduce?

  • Bugfix (a non-breaking change that fixes an issue)
  • New feature (a non-breaking change that adds functionality)
  • Breaking change (a change that causes existing functionality not to work as expected)
  • Optimization
  • Refactoring
  • Documentation update
  • Build-related changes
  • Other: Description

Testing

Requires testing

  • Yes
  • No

No regressions in hive consensus tests.

If yes, did you write tests?

  • Yes
  • No

Documentation

Requires documentation update

  • Yes
  • No

Requires explanation in Release Notes

  • Yes
  • No

Copy link
Copy Markdown
Member

@LukaszRozmej LukaszRozmej left a comment

Choose a reason for hiding this comment

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

Please run hive tests as sometimes order matters

@flcl42
Copy link
Copy Markdown
Contributor

flcl42 commented Oct 28, 2025

Order seems to be important, we need to request a hive test. And cover by internal own ones

Copy link
Copy Markdown
Contributor

@tanishqjasoria tanishqjasoria 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 this would result in different access lists and then cause gas mismatch in nested calls.

@Marchhill
Copy link
Copy Markdown
Contributor Author

i think this would result in different access lists and then cause gas mismatch in nested calls.

Are you talking block access lists here? Because yes that's the main point of the change, the BAL would be incorrect without it. In the execution specs popping from the stack always happens at the start of the CALL: https://github.com/ethereum/execution-specs/blob/forks/osaka/src/ethereum/forks/osaka/vm/instructions/system.py#L365

Could you expand on why it could cause a gas mismatch?

@tanishqjasoria
Copy link
Copy Markdown
Contributor

i think this would result in different access lists and then cause gas mismatch in nested calls.

Are you talking block access lists here? Because yes that's the main point of the change, the BAL would be incorrect without it. In the execution specs popping from the stack always happens at the start of the CALL: https://github.com/ethereum/execution-specs/blob/forks/osaka/src/ethereum/forks/osaka/vm/instructions/system.py#L365

Could you expand on why it could cause a gas mismatch?

i was taking about mismatch because of this - https://github.com/ethereum/execution-specs/blob/forks/osaka/src/ethereum/forks/osaka/vm/instructions/system.py#L376
if we fail before adding the to address to accessed_addresses, then if in the same transaction we try to charge for the same address again, then we would not charge the warm gas but the cold gas. But if it is like this in the spec maybe this case never arises?

@LukaszRozmej
Copy link
Copy Markdown
Member

please observe if no regressions in hive tests

Copy link
Copy Markdown
Contributor

@tanishqjasoria tanishqjasoria left a comment

Choose a reason for hiding this comment

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

we revert access tracker when the call fails.

@Marchhill
Copy link
Copy Markdown
Contributor Author

please observe if no regressions in hive tests

setting up a machine to check this before merging, will take quite a few hours to run

Copy link
Copy Markdown
Contributor

@flcl42 flcl42 left a comment

Choose a reason for hiding this comment

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

Unit tests that confirm outcome is not changed when running this code part with not enough items in stack/underfunded account

@Marchhill
Copy link
Copy Markdown
Contributor Author

Unit tests that confirm outcome is not changed when running this code part with not enough items in stack/underfunded account

@flcl42 you think it needs changes?

@flcl42
Copy link
Copy Markdown
Contributor

flcl42 commented Oct 29, 2025

Unit tests that confirm outcome is not changed when running this code part with not enough items in stack/underfunded account

@flcl42 you think it needs changes?

Yes, the pr lacks unit tests?

@Marchhill
Copy link
Copy Markdown
Contributor Author

Unit tests that confirm outcome is not changed when running this code part with not enough items in stack/underfunded account

@flcl42 you think it needs changes?

Yes, the pr lacks unit tests?

Added some unit tests and confirmed no regressions in hive consensus tests

@LukaszRozmej LukaszRozmej requested a review from flcl42 October 29, 2025 22:40
@Marchhill Marchhill marked this pull request as draft October 30, 2025 13:11
@Marchhill Marchhill marked this pull request as ready for review November 3, 2025 13:31
@Marchhill Marchhill merged commit f6efa71 into master Nov 3, 2025
143 of 145 checks passed
@Marchhill Marchhill deleted the optimise-stack-underflow-call branch November 3, 2025 13:32
kamilchodola added a commit that referenced this pull request Nov 9, 2025
* Add more logging in MultiSyncModeSelector (#9616)

* Add more logging

* fix for seq

* feat: Add configurable EIP-2935 ring buffer size (#9611)

* Blockchain Engine Tests support (#9394)

* initial commit

* fix normal blockchain tests

* tidy

* restore disposes

* comment out BALs

* fix var declaration

* don't set basefeepergas if null

* use network from genesis in blockchain test

* update blockchain test base

* add tracer to blockchain tests runner

* tidy

* tidy

* add genesis processing timeout

* check for null head block

* try undo some changes

* detect failure to process genesis

* check removal is error

* add back checks for genesis spec

* only add noenginerequeststracker in tests

* comment sealed block check

* try remove timeout

* only configure merge for engine tests

* fix merge module init

* add back timeout and remove sealer

* await new payloads

* use reflection for engine rpc method calling

---------

Co-authored-by: Marc Harvey-Hill <10379486+Marchhill@users.noreply.github.com>

* use zero address when from address not specified in rpc calls (#9578)

* use zero address for null values

* small test

* fix proof rpc

* fix test and add more changes

* Allow serving snap requests for more than 128 blocks (#9602)

* Initial plan

* Add SnapServingMaxDepth configuration and update LastNStateRootTracker

Co-authored-by: tanishqjasoria <11698398+tanishqjasoria@users.noreply.github.com>

* Add clarifying comments for configuration changes

Co-authored-by: tanishqjasoria <11698398+tanishqjasoria@users.noreply.github.com>

* Get reorgDepth from config instead of hardcoding in test

Co-authored-by: LukaszRozmej <12445221+LukaszRozmej@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tanishqjasoria <11698398+tanishqjasoria@users.noreply.github.com>
Co-authored-by: Tanishq Jasoria <jasoriatanishq@gmail.com>
Co-authored-by: LukaszRozmej <12445221+LukaszRozmej@users.noreply.github.com>

* Remove console log from FileTestsSource (#9622)

Removed console log for loading test file.

* Correct docs value for Blocks.BlockProductionMaxTxKilobytes (#9620)

* Update OP Superchain chains (#9629)

Co-authored-by: emlautarom1 <emlautarom1@users.noreply.github.com>

* Auto-update fast sync settings (#9628)

Co-authored-by: rubo <rubo@users.noreply.github.com>

* feat: write AckMessage directly to IByteBuffer without temp array (#9623)

* Optimize Ripemd (#9627)

* Allow precompile cache to be switched off by config (#9633)

* Mainnet Osaka, BPO1, BPO2 forks (#9615)

* Change rlp limits and add logs (#9631)

* log rlp guard messages

* Adding stack trace

* Increase receipts limit to 1024

* fix for stack trace

* try fix multiline

* fix

* whitespace

* try fix

* More logs and potential fixes

* log fix

* Revert "More logs and potential fixes"This reverts commit ec71c87.# Conflicts:#	src/Nethermind/Nethermind.Network/MessageSerializationService.csRevert "log fix"This reverts commit b3b1f5f.

Revert "More logs and potential fixes"

This reverts commit ec71c87.

* try weird fix

* Revert "try weird fix"

This reverts commit 0bdfb3d.

* revert packages.json

* simplify log

* Don't abbreviate ForkchoiceStateV1 hashes

* revert spammy ForkchoiceStateV1

* Fix missed dispose on StorageRange in ProgressTracker

* fix test

* Optimise CALL by throwing stack underflow earlier (#9581)

* fail fast

* add unit tests

---------

Co-authored-by: Marc Harvey-Hill <10379486+Marchhill@users.noreply.github.com>

* Optimize BN254Pairing call (#9621)

* Optimize BN254Pairing call

* Don't modify input

* Skip locals

* Tweak inlining

* Update src/Nethermind/Nethermind.Evm.Precompiles/BN254.cs

Co-authored-by: Lukasz Rozmej <lukasz.rozmej@gmail.com>

* Less fixed

* Optimize

* Optimize

* formatting

* formatting

* Tidy

* Use constants

* Feedback

* Skip init

* Faster

* More skip init

* Make mul ReadOnlySpan, add comments

* Simplify

* Skip locals

* Ruben making me work for it

* More working for it

* Still working for it

* Update benchmarks

* Apply suggestions from code review

Co-authored-by: Marc <Marchhill@users.noreply.github.com>

* Feedback

---------

Co-authored-by: Lukasz Rozmej <lukasz.rozmej@gmail.com>
Co-authored-by: Marc <Marchhill@users.noreply.github.com>

* Update OP Superchain chains (#9643)

Co-authored-by: LukaszRozmej <LukaszRozmej@users.noreply.github.com>

* Log/decrease noise (#9642)

* decrease Ethash cache miss log

* Decrease block downloader invalid bloc log

* Update X handle (#9634)

* Better logs on invalid orphan (#9641)

* Try fixing world wrong block

* not this, so keep validating Withdrawals

* Update all op chain configs (#9645)

* update configs

* update all configs

* Add `NetworkId` flag to `InitConfig` (#9476)

* add flag with networkId

* cosmetic

* Update src/Nethermind/Nethermind.Api/IInitConfig.cs

Co-authored-by: Ruben Buniatyan <rubo@users.noreply.github.com>

* fix

* # Conflicts:
#	src/Nethermind/Nethermind.Api/IInitConfig.cs
#	src/Nethermind/Nethermind.Api/InitConfig.cs

* Revert "# Conflicts:"

This reverts commit 7f25638.

* postmerge fix

* Apply suggestion from @benaadams

---------

Co-authored-by: Ruben Buniatyan <rubo@users.noreply.github.com>
Co-authored-by: Ben {chmark} Adams <thundercat@illyriad.co.uk>

* Revert "HACK: enable in fusaka"

This reverts commit 7cfad14.

* HACK: enable in pectra

---------

Co-authored-by: Lukasz Rozmej <lukasz.rozmej@gmail.com>
Co-authored-by: Daniil Ankushin <ankushin.daniil42@gmail.com>
Co-authored-by: Marc <Marchhill@users.noreply.github.com>
Co-authored-by: Marc Harvey-Hill <10379486+Marchhill@users.noreply.github.com>
Co-authored-by: Tanishq Jasoria <jasoriatanishq@gmail.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tanishqjasoria <11698398+tanishqjasoria@users.noreply.github.com>
Co-authored-by: LukaszRozmej <12445221+LukaszRozmej@users.noreply.github.com>
Co-authored-by: Ben {chmark} Adams <thundercat@illyriad.co.uk>
Co-authored-by: core-repository-dispatch-app[bot] <173070810+core-repository-dispatch-app[bot]@users.noreply.github.com>
Co-authored-by: emlautarom1 <emlautarom1@users.noreply.github.com>
Co-authored-by: rubo <rubo@users.noreply.github.com>
Co-authored-by: VolodymyrBg <aqdrgg19@gmail.com>
Co-authored-by: LukaszRozmej <LukaszRozmej@users.noreply.github.com>
Co-authored-by: Marcin Sobczak <77129288+marcindsobczak@users.noreply.github.com>
Co-authored-by: Marcin Sobczak <marcindsobczak@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants