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/program: create evm programming utility #30725

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

holiman
Copy link
Contributor

@holiman holiman commented Nov 4, 2024

In many cases, we have a need to create somewhat nontrivial bytecode. A recent example is the verkle statetests, where we want a CREATE2- op to create a contract, which can then be invoked, and when invoked does a selfdestruct-to-self.

It is overkill to go full solidity, but it is also a bit tricky do assemble this by concatenating bytes. This PR takes an approach that I've been using in goevmlab for several years.

Using this utility, the case can be expressed as:

	// Some runtime code
	runtime := program.New().Ops(vm.ADDRESS, vm.SELFDESTRUCT).Bytecode()
	// A constructor returning the runtime code
	initcode := program.New().ReturnData(runtime).Bytecode()
	// A factory invoking the constructor
	outer := program.New().Create2AndCall(initcode, nil).Bytecode()

We have a lot of places in the codebase where we concatenate bytes, cast from vm.OpCode . If we use this approach, we can make those places a bit more maintainable/robust.

WDYT?

Note: I could have just added a dependency to goevmlab Program. However, goevmlab depends on go-ethereum, and I'd rather just avoid the potential cycle problems.

@MariusVanDerWijden
Copy link
Member

I like this very much, I've been using goevmlab.Program for a few years in a bunch of scenarios for reproducing and writing tests. Moving this upstream would also allow me to get rid of the goevmlab dependencies in FuzzyVM and make the dependency mgmt in case of a hardfork much easier

@karalabe
Copy link
Member

karalabe commented Nov 4, 2024

As long as we're not promising API stability and are willing to massively iterate on this if needed, I'm happy about it.

@holiman
Copy link
Contributor Author

holiman commented Nov 4, 2024

not promising API stability and are willing to massively iterate on this if needed

Yeah, definitely. We should make it explicit, though. I'll add some documentation to that effect

@MariusVanDerWijden
Copy link
Member

lint failed

Copy link
Member

@lightclient lightclient left a comment

Choose a reason for hiding this comment

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

Generally like this a lot.

core/vm/program/program.go Show resolved Hide resolved
core/vm/program/program.go Outdated Show resolved Hide resolved
core/vm/program/program.go Outdated Show resolved Hide resolved
core/vm/program/program.go Outdated Show resolved Hide resolved
core/vm/program/program.go Outdated Show resolved Hide resolved
core/vm/program/program.go Outdated Show resolved Hide resolved
core/vm/program/program.go Outdated Show resolved Hide resolved
core/vm/program/program.go Outdated Show resolved Hide resolved
core/vm/program/program.go Outdated Show resolved Hide resolved
core/vm/program/program.go Outdated Show resolved Hide resolved
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.

4 participants