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

Add EOF container validation script #3553

Merged
merged 7 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions packages/evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@
"@ethereumjs/statemanager": "^2.3.0",
"@ethereumjs/tx": "^5.3.0",
"@ethereumjs/util": "^9.0.3",
"@noble/curves": "^1.4.2",
"@types/debug": "^4.1.9",
"debug": "^4.3.3",
"ethereum-cryptography": "^2.2.1",
"@noble/curves": "^1.4.2",
"rustbn-wasm": "^0.4.0"
},
"devDependencies": {
Expand All @@ -81,7 +81,8 @@
"minimist": "^1.2.5",
"node-dir": "^0.1.17",
"rollup-plugin-visualizer": "^5.12.0",
"solc": "^0.8.1"
"solc": "^0.8.1",
"split": "^1.0.1"
},
"engines": {
"node": ">=18"
Expand Down
36 changes: 36 additions & 0 deletions packages/evm/scripts/eofContainerValidator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Common, Hardfork, Mainnet } from '@ethereumjs/common'
import { unprefixedHexToBytes } from '@ethereumjs/util'
import split from 'split'

import { createEVM, validateEOF } from '../src/index.js'

/**
* This script reads hex strings (either prefixed or non-prefixed with 0x) from stdin
* It tries to validate the EOF container, if it is valid, it will print "OK"
* If there is a validation error, it will print "err: <REASON>"
* If the input is emtpy, the program will exit
*/

const common = new Common({ chain: Mainnet })
common.setHardfork(Hardfork.Prague)
common.setEIPs([663, 3540, 3670, 4200, 4750, 5450, 6206, 7069, 7480, 7620, 7692, 7698])
const evm = await createEVM({ common })

function processLine(line) {
if (line.length === 0) {
process.exit()
}
let trimmed = line
if (line.startsWith('0x')) {
trimmed = line.slice(2)
}
const bytes = unprefixedHexToBytes(trimmed)
try {
validateEOF(bytes, evm)
console.log('OK')
} catch (e: any) {
console.log('err: ' + e.message)
}
}

process.stdin.pipe(split()).on('data', processLine)
3 changes: 3 additions & 0 deletions packages/evm/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { EOFContainer, validateEOF } from './eof/container.js'
import { EVM } from './evm.js'
import { ERROR as EVMErrorMessage, EvmError } from './exceptions.js'
import { Message } from './message.js'
Expand Down Expand Up @@ -36,6 +37,7 @@ export type {
}

export {
EOFContainer,
EVM,
EvmError,
EVMErrorMessage,
Expand All @@ -44,6 +46,7 @@ export {
MCLBLS,
Message,
NobleBLS,
validateEOF,
}

export * from './constructors.js'
Expand Down
Loading