-
Notifications
You must be signed in to change notification settings - Fork 20.4k
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
core/vm: Make INVALID a defined opcode #24017
Conversation
core/vm/errors.go
Outdated
@@ -36,6 +36,7 @@ var ( | |||
ErrGasUintOverflow = errors.New("gas uint64 overflow") | |||
ErrInvalidCode = errors.New("invalid code: must not begin with 0xef") | |||
ErrNonceUintOverflow = errors.New("nonce uint64 overflow") | |||
ErrInvalidOpcode = errors.New("exection reached INVALID (0xfe) opcode") |
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.
ErrInvalidOpcode = errors.New("exection reached INVALID (0xfe) opcode") | |
ErrInvalidOpcode = errors.New("execution reached INVALID (0xfe) opcode") |
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.
Could also just say:
ErrInvalidOpcode = errors.New("exection reached INVALID (0xfe) opcode") | |
ErrInvalidOpcode = errors.New("aborted with INVALID (0xfe) opcode") |
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.
Lastly with EIP-1803 I hope we can rename INVALID
to ABORT
to make it more clear, but that should be a separate PR I suppose?
2676eda
to
e2aefed
Compare
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.
Overall, I'm not quite convinced about the need for doing this. Can you elaborate on that?
core/vm/errors.go
Outdated
@@ -36,6 +36,7 @@ var ( | |||
ErrGasUintOverflow = errors.New("gas uint64 overflow") | |||
ErrInvalidCode = errors.New("invalid code: must not begin with 0xef") | |||
ErrNonceUintOverflow = errors.New("nonce uint64 overflow") | |||
ErrInvalidOpcode = errors.New("aborted with INVALID (0xfe) opcode") |
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.
We already have an ErrInvalidOpCode
, as a type
, defined further down in this file. Having a type with the same name as a global var
is not a good idea.
IMO let's not define a new specific error for this specific opcode -- the idea with 0xFE
is that it will always remain undefined. There are others currently undefined, and IMO this opcode should be treated exactly like those, by the EVM.
So I think we can skip this var
here. And the opInvaid
could just do
return nil, &ErrInvalidOpCode{opcode: OpCode(0xfe)}
With EOF we propose (in EIP-3670) to forbid deploying undefined opcodes (which will allow introducing new opcodes later without bumping EOF version and also simplifies EVM implementation, where it needs only EOF version (without additional revision) to know if particular byte value is defined)
Also a minor point: having an enum value for |
And I have EIP-3670 implementation where I use |
e2aefed
to
3180e4f
Compare
core/vm/jump_table.go
Outdated
INVALID: { | ||
execute: opInvalid, | ||
constantGas: 0, | ||
minStack: minStack(0, 0), | ||
maxStack: maxStack(0, 0), | ||
}, |
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.
Though -- in the context of what you're implementing in that other PR... Is it really necessary to define it as an acutal op in the jumptable, as opposed to just define the OpCode
but leave it empty in the jumptable?
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.
I think it's better to have it in the jumptable, I see the question of whether 0xfe is a defined opcode as a property of particular fork rules (currently it's defined in all forks, but theoretically 0xfe might mean something else in some other jump table)
Without putting it into jumptable I can only think of having it as a special case in code validation, like jumpTable[opcode] == nil && opcode != 0xfe
will mean it's not defined.
3180e4f
to
f8997b5
Compare
As discussed with @gumb0, |
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.
LGTM
* core/vm: Define 0xfe opcode as INVALID * core/vm: Remove opInvalid as opUndefined handles it Co-authored-by: Alex Beregszaszi <[email protected]>
* core/vm: Define 0xfe opcode as INVALID * core/vm: Remove opInvalid as opUndefined handles it Co-authored-by: Alex Beregszaszi <[email protected]>
* core/vm: Define 0xfe opcode as INVALID * core/vm: Remove opInvalid as opUndefined handles it Co-authored-by: Alex Beregszaszi <[email protected]>
core/vm: Make INVALID a defined opcode (ethereum#24017) * core/vm: Define 0xfe opcode as INVALID * core/vm: Remove opInvalid as opUndefined handles it Co-authored-by: Alex Beregszaszi <[email protected]> Co-authored-by: Andrei Maiboroda <[email protected]> Co-authored-by: Alex Beregszaszi <[email protected]>
Cherry-pick ethereum/go-ethereum#24017. * core/vm: Define 0xfe opcode as INVALID * core/vm: Remove opInvalid as opUndefined handles it Co-authored-by: Alex Beregszaszi <[email protected]> Co-authored-by: Andrei Maiboroda <[email protected]> Co-authored-by: Alex Beregszaszi <[email protected]>
* core/vm: Define 0xfe opcode as INVALID * core/vm: Remove opInvalid as opUndefined handles it Co-authored-by: Alex Beregszaszi <[email protected]>
This doesn't change anything except error message,
but will be required for EOF code calidation (EIP-3670)It doesn't solve the needs of EIP-3670 anymore (because undefined and INVALID are not distinguished in jump table), but does improve the traces.Before:
After: