Skip to content

Commit

Permalink
core/vm/program: evm bytecode-building utility (ethereum#30725)
Browse files Browse the repository at this point in the history
In many cases, there is 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
has been used in in goevmlab for several years.

Using this utility, the case can be expressed as: 
```golang
	// 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` . By taking tihs approach instead, thos places can be made a
bit more maintainable/robust.
  • Loading branch information
holiman authored Nov 20, 2024
1 parent aa63692 commit 6d3d252
Show file tree
Hide file tree
Showing 4 changed files with 840 additions and 195 deletions.
Loading

0 comments on commit 6d3d252

Please sign in to comment.