-
Notifications
You must be signed in to change notification settings - Fork 838
EVM: error handling #3714
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
Draft
jochem-brouwer
wants to merge
11
commits into
master
Choose a base branch
from
evm-error-handling
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
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
EVM: error handling #3714
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d00b7bf
evm/util: error overhaul
jochem-brouwer 71e77dc
evm: fix err handling
jochem-brouwer b4458d7
Merge branch 'master' into evm-error-handling
jochem-brouwer 293f4cc
Merge branch 'master' into evm-error-handling
jochem-brouwer 70b2df5
Merge branch 'master' into evm-error-handling
jochem-brouwer ec01f1b
util: update base error class
jochem-brouwer 16d1b38
evm/util: update to new, simpler error format
jochem-brouwer aa3702b
vm/client: fix build
jochem-brouwer a8cd9e1
util: introduce new temp error with unset error code
jochem-brouwer 1e97567
Merge branch 'master' into evm-error-handling
jochem-brouwer 85aa5fa
lint: add rule to disallow `new Error` throwing
jochem-brouwer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,4 +1,9 @@ | ||
| export enum ERROR { | ||
| import { EthereumJSError } from '@ethereumjs/util' | ||
|
|
||
| import type { EOFError } from './eof/errors.js' | ||
|
|
||
| // TODO: merge EOF errors in here | ||
| export enum RuntimeErrorMessage { | ||
| OUT_OF_GAS = 'out of gas', | ||
| CODESTORE_OUT_OF_GAS = 'code store out of gas', | ||
| CODESIZE_EXCEEDS_MAXIMUM = 'code size to deposit exceeds maximum code size', | ||
|
|
@@ -15,13 +20,11 @@ export enum ERROR { | |
| REFUND_EXHAUSTED = 'refund exhausted', | ||
| VALUE_OVERFLOW = 'value overflow', | ||
| INSUFFICIENT_BALANCE = 'insufficient balance', | ||
| INVALID_BEGINSUB = 'invalid BEGINSUB', | ||
| INVALID_RETURNSUB = 'invalid RETURNSUB', | ||
| INVALID_JUMPSUB = 'invalid JUMPSUB', | ||
| INVALID_BYTECODE_RESULT = 'invalid bytecode deployed', | ||
| INITCODE_SIZE_VIOLATION = 'initcode exceeds max initcode size', | ||
| INVALID_INPUT_LENGTH = 'invalid input length', | ||
| INVALID_EOF_FORMAT = 'invalid EOF format', | ||
| INVALID_PRECOMPILE = 'invalid precompile', | ||
|
|
||
| // BLS errors | ||
| BLS_12_381_INVALID_INPUT_LENGTH = 'invalid input length', | ||
|
|
@@ -38,12 +41,38 @@ export enum ERROR { | |
| INVALID_PROOF = 'kzg proof invalid', | ||
| } | ||
|
|
||
| export class EvmError { | ||
| error: ERROR | ||
| errorType: string | ||
| export enum EvmErrorCode { | ||
| UNSUPPORTED_FEATURE = 'EVM_ERROR_UNSUPPORTED_FEATURE', | ||
| RUNTIME_ERROR = 'EVM_ERROR_RUNTIME_ERROR', | ||
| } | ||
|
|
||
| type EvmRuntimeErrorType = { | ||
| code: EvmErrorCode.RUNTIME_ERROR | ||
| reason: RuntimeErrorMessage | EOFError | ||
| } & ( | ||
| | { reason: RuntimeErrorMessage.REVERT; revertBytes: Uint8Array } | ||
| | { reason: Exclude<RuntimeErrorMessage, RuntimeErrorMessage.REVERT> | EOFError } | ||
| ) | ||
|
|
||
| export type EvmErrorType = { code: EvmErrorCode.UNSUPPORTED_FEATURE } | EvmRuntimeErrorType | ||
|
|
||
| constructor(error: ERROR) { | ||
| this.error = error | ||
| this.errorType = 'EvmError' | ||
| export class EvmError extends EthereumJSError<EvmErrorType> { | ||
|
||
| constructor(type: EvmErrorType, message?: string) { | ||
| super(type, message) | ||
| } | ||
| } | ||
|
|
||
| export function getRuntimeError(error: EvmError): RuntimeErrorMessage | EOFError | undefined { | ||
| if (error.type.code === EvmErrorCode.RUNTIME_ERROR) { | ||
| return error.type.reason | ||
| } | ||
| } | ||
|
|
||
| /* | ||
| throw new EvmError({ | ||
| code: EvmErrorCode.RUNTIME_ERROR, | ||
| reason: RuntimeErrorMessage.REVERT | ||
| }) | ||
|
|
||
|
|
||
| */ | ||
This file contains hidden or 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 hidden or 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
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.
Is this scalable? I'm wondering how this would look if we had multiple error codes with corresponding different formats. Right now we're just having one case for "RuntimeErrorMessage.REVERT" and another excluding "RuntimeErrorMessage.REVERT", but I wonder if that might become too burdensome if we need to exclude more
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.
This was some experimenting with the typescript typing I did. It ensures that if
reasonisRuntimeErrorMessage.REVERTit has the mandatoryrevertBytes. If is NOT aREVERTthen the reason could be any of theRuntimeErrorMessageor an EOFError.Note: EOFError has not been migrated to the EvmError, likely when I do that this typing (the second line) does not have to be there (will check)
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.
This typing (I checked) is just to type the evm errors such that the REVERT error has a
revertBytesfield. It is straightforward to add new error codes or new error reasons, or the inject specific error which adds context (like the mandatoryrevertBytesfield in theREVERTerror)