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

EVM: bump opcode coverage + add performance tester #3198

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

jochem-brouwer
Copy link
Member

@jochem-brouwer jochem-brouwer commented Dec 15, 2023

The goal of this PR is to:

  • Add basic test coverage of most opcodes
  • Use the code ran in these tests to generate a profile report of the EVM

The goal of this PR is to create both simple opcode tests (compare stack/memory/storage output to expected code), with transparant bytecode generation. Some (all?) of these tests are also used in the profiler report, which tries edge cases (adding maximal numbers together, exponentation to the max, etc.) and reports MGas/S output of those. This can be used to spot slow/fast variants of certain opcodes, or identify which opcodes need some optimization.

Sample profile report output:

image

To run the tests, run npm run profiler:report. You need to have tsx installed for this, so npm i -g tsx. Note: the default gas limit for each test is 30M, and currently all opcodes keep looping until this gas limit is reached (this is slow). There is a progress report though so one can track how much time it should take to finish.

WIP

Copy link

codecov bot commented Dec 15, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (3981bca) 88.99% compared to head (9d7b806) 89.64%.

Additional details and impacted files

Impacted file tree graph

Flag Coverage Δ
block ?
blockchain ?
client 84.63% <ø> (?)
common ?
devp2p ?
ethash ?
evm ?
genesis 99.98% <ø> (ø)
statemanager ?
trie ?
util ?
vm ?
wallet 91.00% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

@acolytec3
Copy link
Contributor

This looks great but we should merge #3198 before merging this one. It's not obvious to me but are these opcode tests also run by CI?

const code = makeLoopCode(
createBytecode([createOpcodeTest(test.stack, opcodeName, 'none'), POP])
)
const evm = new EVM({ common, profiler: { enabled: true } })
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const evm = new EVM({ common, profiler: { enabled: true } })
common.events.removeAllListeners()

Since we're reusing the same common each time, we should clear listeners because the evm adds a new listener here and I see memory leak errors when I run the profiler script.

@jochem-brouwer jochem-brouwer marked this pull request as draft December 26, 2023 23:28
@holgerd77
Copy link
Member

@jochem-brouwer What is the status of this PR?

@jochem-brouwer
Copy link
Member Author

I intend to finish this one this month. The goal is to write basic tests for all opcodes and provide a test framework.

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.

None yet

3 participants