Skip to content
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

Introducing OptimizedStack based on uint256 integers. #156

Merged
merged 15 commits into from
Mar 28, 2024
Merged

Introducing OptimizedStack based on uint256 integers. #156

merged 15 commits into from
Mar 28, 2024

Conversation

cokicm
Copy link

@cokicm cokicm commented Mar 13, 2024

Description

Previous version of stack was made as an array of pointers to big.int instances. This PR introduces new stack that uses uint256 values based stack for improved performance.

Changes include

  • Bugfix (non-breaking change that solves an issue)
  • Hotfix (change that solves an urgent issue, and requires immediate attention)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (change that is not backwards-compatible and/or changes current functionality)

Checklist

  • I have assigned this PR to myself
  • I have added at least 1 reviewer
  • I have added the relevant labels
  • I have updated the official documentation
  • I have added sufficient documentation in code

Testing

  • I have tested this code with the official test suite
  • I have tested this code manually

@cokicm cokicm self-assigned this Mar 13, 2024
Copy link
Collaborator

@goran-ethernal goran-ethernal left a comment

Choose a reason for hiding this comment

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

This is very nice work. Left comments, nothing big. Please keep in mind of the Lint errors that are being reported.

state/runtime/evm/instructions.go Outdated Show resolved Hide resolved
state/runtime/evm/instructions.go Outdated Show resolved Hide resolved
state/runtime/evm/instructions.go Outdated Show resolved Hide resolved
state/runtime/evm/instructions.go Outdated Show resolved Hide resolved
state/runtime/evm/state.go Outdated Show resolved Hide resolved
state/runtime/evm/instructions.go Show resolved Hide resolved
state/runtime/evm/instructions.go Show resolved Hide resolved
state/runtime/evm/instructions.go Show resolved Hide resolved
state/runtime/evm/instructions.go Outdated Show resolved Hide resolved
state/runtime/evm/instructions.go Outdated Show resolved Hide resolved
cokicm and others added 3 commits March 19, 2024 21:03
…ith unrolled loop. This allows CPU to execute multiple instructions in parallel providing >200% increased speed compared to uint256.WriteToSlice() implementation. If needed, can be additionally implemented for different array lengths.
@cokicm
Copy link
Author

cokicm commented Mar 19, 2024

TODO:

  • Check if sp field field can be removed from optimized stack.
  • Agree on error handling within optimized stack

go.mod Outdated Show resolved Hide resolved
state/runtime/evm/dispatch_table_test.go Show resolved Hide resolved
state/runtime/evm/instructions_benchmark_test.go Outdated Show resolved Hide resolved
state/runtime/evm/instructions_benchmark_test.go Outdated Show resolved Hide resolved
state/runtime/evm/instructions_benchmark_test.go Outdated Show resolved Hide resolved
state/runtime/evm/instructions.go Outdated Show resolved Hide resolved
state/runtime/evm/instructions.go Outdated Show resolved Hide resolved
@Stefan-Ethernal Stefan-Ethernal changed the base branch from develop to feat/evm-optimized-stack March 28, 2024 09:31
@Stefan-Ethernal Stefan-Ethernal merged commit 8ca41b1 into Ethernal-Tech:feat/evm-optimized-stack Mar 28, 2024
10 checks passed
goran-ethernal added a commit that referenced this pull request Apr 16, 2024
* Introducing OptimizedStack based on uint256 integers.

* Replacing big.int with uint256 for jump instruction.

* Update state/runtime/evm/instructions.go

Co-authored-by: Goran Rojovic <[email protected]>

* Code review fixes.

* opMStore is changed to use newly introduced WriteToSlice() function with unrolled loop. This allows CPU to execute multiple instructions in parallel providing >200% increased speed compared to uint256.WriteToSlice() implementation. If needed, can be additionally implemented for different array lengths.

* Fixing linter errors.

* setBytes to use uint256 instead of big.int.

* Fixing linter errors.

* Go mod tidy

* Lint fix

* Revert go version

* Address comments

* Remove pointer dereferencing and use value type reference

---------

Co-authored-by: Goran Rojovic <[email protected]>
Co-authored-by: Stefan Negovanović <[email protected]>
Stefan-Ethernal added a commit that referenced this pull request May 29, 2024
* Introducing OptimizedStack based on uint256 integers (#156)

* Introducing OptimizedStack based on uint256 integers.

* Replacing big.int with uint256 for jump instruction.

* Update state/runtime/evm/instructions.go

Co-authored-by: Goran Rojovic <[email protected]>

* Code review fixes.

* opMStore is changed to use newly introduced WriteToSlice() function with unrolled loop. This allows CPU to execute multiple instructions in parallel providing >200% increased speed compared to uint256.WriteToSlice() implementation. If needed, can be additionally implemented for different array lengths.

* Fixing linter errors.

* setBytes to use uint256 instead of big.int.

* Fixing linter errors.

* Go mod tidy

* Lint fix

* Revert go version

* Address comments

* Remove pointer dereferencing and use value type reference

---------

Co-authored-by: Goran Rojovic <[email protected]>
Co-authored-by: Stefan Negovanović <[email protected]>

* Updating tracer to use optimized stack directly, instead of big.int.

* Removing remaining big.int references from instructions.go and state.go where possible. Removing unused functions and constants.

* Adding error handling for invalid balance and invalid message value.

* Adding benchmark tests for OptimizedStack.

* Group dependencies

* Fixing state error code name for errInvalidBalanceValue.

---------

Co-authored-by: cokicm <[email protected]>
Co-authored-by: Goran Rojovic <[email protected]>
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.

3 participants