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

core/vm: deep copy jumptable when enabling extra eips #26137

Merged
merged 8 commits into from
Nov 9, 2022

Conversation

yihuang
Copy link
Contributor

@yihuang yihuang commented Nov 8, 2022

Closes: #26136
Thanks: @mmsqe

yihuang added a commit to yihuang/ethermint that referenced this pull request Nov 8, 2022
When there's extra-eips, concurrent query could cause non-deterministic evm execution result.
It could affect even if exists in historical states.

Ref: ethereum/go-ethereum#26137
yihuang added a commit to yihuang/ethermint that referenced this pull request Nov 8, 2022
When there's extra-eips, concurrent query could cause non-deterministic evm execution result.
It could affect even if exists in historical states.

Ref: ethereum/go-ethereum#26137
@holiman
Copy link
Contributor

holiman commented Nov 8, 2022

The NewEVMInterpreter + extra eips is not meant for production use, but rather to run or generate tests. In any scenario where an actual production hardfork is configured, a separate instruction table is created, and the changes applied to that instruction table. Like this:

func newIstanbulInstructionSet() JumpTable {

All the instruction tables are separate, and defined here:

I'm interested in the root issue reported in #26136, what the actual background is where this was found to be a problem @yihuang ?

@yihuang
Copy link
Contributor Author

yihuang commented Nov 8, 2022

I'm interested in the root issue reported in #26136, what the actual background is where this was found to be a problem @yihuang ?

it's used in ethermint

@@ -83,14 +83,14 @@ func NewEVMInterpreter(evm *EVM, cfg Config) *EVMInterpreter {
}
var extraEips []int
for _, eip := range cfg.ExtraEips {
Copy link
Contributor

Choose a reason for hiding this comment

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

		if len(cfg.ExtraEips) > 0 {
			// Deep-copy jumptable to prevent modification of opcodes in other tables
			cfg.JumpTable := copyJumpTable(cfg.JumpTable)
		}
		for _, eip := range cfg.ExtraEips {
			if err := EnableEIP(eip, &cfg.JumpTable); err != nil {
				// Disable it, so caller can check if it's activated or not
				log.Error("EIP activation failed", "eip", eip, "error", err)
			} else {
				extraEips = append(extraEips, eip)
			}
		}

Would this work? No need to deep-copy it multiple times

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the original one also prevents a partial write if EnableEIP returns an error in the middle.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, the original one set cfg.JumpTable unconditionally, so it don't prevent a partial write neither.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. Doesn't matter a whole lot, this is not a hot path (for us)

Copy link
Contributor Author

@yihuang yihuang Nov 8, 2022

Choose a reason for hiding this comment

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

And there's no partial write to prevent anyway, I just changed to your version.

core/vm/jump_table.go Outdated Show resolved Hide resolved
@holiman holiman changed the title fix: jump table is not deep copied when enable extra eips core/vm: deep copy jumptable when enabling extra eips Nov 8, 2022
Co-authored-by: Martin Holst Swende <[email protected]>
core/vm/jump_table_test.go Outdated Show resolved Hide resolved
core/vm/jump_table_test.go Outdated Show resolved Hide resolved
@@ -83,14 +83,14 @@ func NewEVMInterpreter(evm *EVM, cfg Config) *EVMInterpreter {
}
var extraEips []int
for _, eip := range cfg.ExtraEips {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. Doesn't matter a whole lot, this is not a hot path (for us)

yihuang and others added 3 commits November 8, 2022 17:15
Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

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

LGTM. IMO this change makes EVM modifications less of a footgun, it might save us from a long debug session at some point.

core/vm/jump_table_test.go Outdated Show resolved Hide resolved
@holiman holiman added this to the 1.11.0 milestone Nov 8, 2022
@holiman holiman merged commit 7dc5e78 into ethereum:master Nov 9, 2022
@holiman holiman removed the pr:merge label Nov 9, 2022
yihuang added a commit to yihuang/ethermint that referenced this pull request Nov 9, 2022
When there's extra-eips, concurrent query could cause non-deterministic evm execution result.
It could affect even if exists in historical states.

Ref: ethereum/go-ethereum#26137
yihuang added a commit to crypto-org-chain/go-ethereum that referenced this pull request Nov 10, 2022
When the interpreter is configured to use extra-eips, this change makes it so that all the opcodes are deep-copied, to prevent accidental modification of the 'base' jumptable.

Closes: ethereum#26136

Co-authored-by: Martin Holst Swende <[email protected]>
JayT106 pushed a commit to JayT106/go-ethereum that referenced this pull request Mar 2, 2023
When the interpreter is configured to use extra-eips, this change makes it so that all the opcodes are deep-copied, to prevent accidental modification of the 'base' jumptable.

Closes: ethereum#26136

Co-authored-by: Martin Holst Swende <[email protected]>
shekhirin pushed a commit to shekhirin/go-ethereum that referenced this pull request Jun 6, 2023
When the interpreter is configured to use extra-eips, this change makes it so that all the opcodes are deep-copied, to prevent accidental modification of the 'base' jumptable. 

Closes: ethereum#26136

Co-authored-by: Martin Holst Swende <[email protected]>
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Sep 26, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Sep 26, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Sep 27, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Oct 17, 2024
gzliudan added a commit to XinFinOrg/XDPoSChain that referenced this pull request Oct 17, 2024
wanwiset25 pushed a commit to XinFinOrg/XDPoSChain that referenced this pull request Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Problem: extra-eips is not concurrency safe
3 participants