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
jochem-brouwer
wants to merge
15
commits into
master
Choose a base branch
from
evm-coverage-performance
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6373df2
evm: add coverage/performance tests framework
jochem-brouwer 76211c5
evm: add arithmetic tests + test framework
jochem-brouwer fca2227
evm: add opcode profiler
jochem-brouwer d361a01
evm: add "profiler:report" script
jochem-brouwer dad4b6b
evm: add bitwise ops tests
jochem-brouwer 1b16f29
evm: profiler add extra log tracker
jochem-brouwer 15f7e17
Merge branch 'master' into evm-coverage-performance
acolytec3 188c426
Merge branch 'evm-coverage-performance' of github.com:ethereumjs/ethe…
jochem-brouwer 18a9022
evm: apply suggestion
jochem-brouwer a292f4a
Merge branch 'master' into evm-coverage-performance
jochem-brouwer cf13ffa
Merge branch 'evm-coverage-performance' of github.com:ethereumjs/ethe…
jochem-brouwer 3c502e9
evm: extra tests and features for opcode tests [no ci]
jochem-brouwer 211e842
evm: add more tests
jochem-brouwer 8d1fe97
evm: add more opcode tests
jochem-brouwer 9d7b806
Merge branch 'master' into evm-coverage-performance
jochem-brouwer File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* eslint no-console: 0 */ | ||
|
||
import { Chain, Common, Hardfork } from '@ethereumjs/common' | ||
import { hexToBytes } from '@ethereumjs/util' | ||
|
||
import { EVM } from '../../src/index.js' | ||
|
||
import { opcodeTests } from './tests.js' | ||
import { | ||
createBytecode, | ||
createOpcodeTest, | ||
getOpcodeByte, | ||
getOpcodeTestName, | ||
makeLoopCode, | ||
} from './utils.js' | ||
|
||
// Config | ||
const hardfork = Hardfork.Shanghai | ||
const GAS_LIMIT = BigInt(30_000_000) // 30M gas (mainnet max gas per block) | ||
// End config | ||
|
||
const GAS_TARGET = 30_000_000 | ||
const SECONDS = 12 | ||
|
||
const MGasPerSecondTarget = GAS_TARGET / SECONDS / 1e6 | ||
|
||
const common = new Common({ chain: Chain.Mainnet, hardfork }) | ||
|
||
let testCount = 0 | ||
for (const testSet in opcodeTests) { | ||
const testCases = opcodeTests[testSet] | ||
for (const opcodeName in testCases) { | ||
const tests = testCases[opcodeName] | ||
for (const _ of tests) { | ||
testCount++ | ||
} | ||
} | ||
} | ||
|
||
const POP = getOpcodeByte('POP') | ||
|
||
const profilerResults: { | ||
testName: string | ||
opcode: string | ||
mGasPerSecond: number | ||
}[] = [] | ||
|
||
let progress = 0 | ||
|
||
async function profile() { | ||
for (const testSet in opcodeTests) { | ||
const testCases = opcodeTests[testSet] | ||
for (const opcodeName in testCases) { | ||
const tests = testCases[opcodeName] | ||
for (const test of tests) { | ||
const testName = getOpcodeTestName(opcodeName, test.stack ?? [], test.name) | ||
const code = makeLoopCode( | ||
createBytecode([createOpcodeTest(test.stack ?? [], opcodeName, 'none'), POP]) | ||
) | ||
common.events.removeAllListeners() | ||
const evm = new EVM({ common, profiler: { enabled: true } }) | ||
await evm.runCode({ | ||
code: hexToBytes(code), | ||
gasLimit: GAS_LIMIT, | ||
}) | ||
const logs = evm.getPerformanceLogs() | ||
for (const item of logs.opcodes) { | ||
if (item.tag === opcodeName) { | ||
profilerResults.push({ | ||
testName, | ||
opcode: opcodeName, | ||
mGasPerSecond: item.millionGasPerSecond, | ||
}) | ||
break | ||
} | ||
} | ||
evm.clearPerformanceLogs() | ||
progress++ | ||
console.log(`Progress: ${progress}/${testCount} [ ${testSet}:${opcodeName} ]`) | ||
} | ||
} | ||
} | ||
const sorted = profilerResults.sort((a, b) => { | ||
return b.mGasPerSecond - a.mGasPerSecond | ||
}) | ||
console.log() | ||
console.log('-------------------------------------------------------------------------') | ||
console.log(`Profiler report for hardfork ${hardfork}, gas limit: ${Number(GAS_LIMIT)}`) | ||
console.log(`Any MGas/s higher than ${MGasPerSecondTarget} is OK`) | ||
console.log('-------------------------------------------------------------------------') | ||
console.log() | ||
console.log('MGas/s'.padEnd(10, ' '), 'Opcode'.padEnd(12, ' '), 'Test name') | ||
console.log('-------------------------------------------------------------------------') | ||
|
||
for (const entry of sorted) { | ||
console.log( | ||
entry.mGasPerSecond.toString().padEnd(10, ' '), | ||
entry.opcode.padEnd(12, ' '), | ||
entry.testName | ||
) | ||
} | ||
} | ||
|
||
void profile() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { describe, it } from 'vitest' | ||
|
||
import { opcodeTests } from './tests.js' | ||
import { runOpcodeTest } from './utils.js' | ||
|
||
for (const testSet in opcodeTests) { | ||
describe(`should test ${testSet} tests`, () => { | ||
const testCases = opcodeTests[testSet] | ||
for (const opcodeName in testCases) { | ||
it(`should test opcode ${opcodeName}`, async () => { | ||
const testDataArray = testCases[opcodeName] | ||
for (const testData of testDataArray) { | ||
await runOpcodeTest({ | ||
testName: testData.name, | ||
opcodeName, | ||
expected: testData.expected, | ||
expectedReturnType: testData.expectedReturnType ?? 'topStack', | ||
input: testData.stack ?? [], // TODO figure out why we have to init this to [], should be overriden by defaults | ||
initMem: testData.initMem, | ||
evmOpts: testData.evmOpts, | ||
preState: testData.preState, | ||
}) | ||
} | ||
}) | ||
} | ||
}) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're reusing the same
common
each time, we should clear listeners because theevm
adds a new listener here and I see memory leak errors when I run the profiler script.